update radio button in PySimpleGUI
Asked Answered
M

1

5

I'm using PySimpleGUI in which I want to update a radio button. According to the documentation the radio button has an update method. But somehow it doesn't work properly.

I wrote the following code which should update the value of the radio button from Test to NewTest. The result is still Test.

Code used below:

import PySimpleGUI as sg

layout1 = [[sg.Radio('Test', "RADIO1", key='_RADIO1_', default=True, font=50)],
    [sg.Button('Ok', font=50), sg.Button('Stop', font=50)]]

window = sg.Window('Read').Layout(layout1).Finalize()

while True:
   window.Element('_RADIO1_').Update('NewTest')
   button, values = window.Read()
   exit()
Mayan answered 10/2, 2019 at 17:23 Comment(0)
K
6

Sounds like you're trying to change the text that's next to an specific radio button.

The problem is that each of the PySimpleGUI Elements has a slightly different Update method. Simply put, the things you can change in a Radio Element are:

Update(self, value=None, disabled=None, visible=None)

While the documentation on the Radio Button element's Update is brief in the documentation, it is described there https://pysimplegui.readthedocs.io/#radio-button-element

Update(value=None, disabled=None, visible=None)
value - bool - if True change to selected
disabled - if True disables the element

There are 3 things you can currently change in a Radio button, the "state" (true/false), disabled and visibility.

I would suggest logging this as a feature request Issue on the GitHub site (http://www.PySimpleGUI.com). These requests are often implemented quite quickly.

Koy answered 11/2, 2019 at 13:31 Comment(2)
Dear @Mike from PSG, Was this feature implemented by now? I am trying to update the state of a set of RB as a result of another GUI event and I don't know how to do it...Humblebee
Come to the PySimpleGUI github and open an issue... someone will be happy to help.Koy

© 2022 - 2024 — McMap. All rights reserved.