简体   繁体   中英

update radio button in PySimpleGUI

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()

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM