问题
I used below approach from this post to hide GUI elements which works very well:
import PySimpleGUIQt as sg
layout = [
[sg.Checkbox('Module Selection', default = False, change_submits= True, key = '_checkbox1_', size=(15,1)),
sg.Text('Module(.xlsx)', size = (15,0.5), auto_size_text = True, justification = 'right', key = '_moduletext_')]
]
window = sg.Window('A2L', layout, icon = u"icon\\index.ico", auto_size_buttons = False).Finalize()
window.Element('_moduletext_').Update(visible = False) #makes the element invisible
values_dict={}
while True: # Event Loop
button, values_dict = window.Read()
if values_dict['_checkbox1_']:
window.Element('_moduletext_').Update(visible = True)
The problem here is that If i replace the checkbox with a radio button then same code doesnt hide the gui element dyanmically.Below is the code with Radio button:
import PySimpleGUIQt as sg
layout = [
[sg.Radio('Module Selection','RADIO' default = False, enable_events = True, key = '_radio1_', size=(15,1)),
sg.Text('Module(.xlsx)', size = (15,0.5), auto_size_text = True, justification = 'right', key = '_moduletext_')]
]
window = sg.Window('A2L', layout, icon = u"icon\\index.ico", auto_size_buttons = False).Finalize()
window.Element('_moduletext_').Update(visible = False) #makes the element invisible
values_dict={}
while True: # Event Loop
button, values_dict = window.Read()
if values_dict['_radio1_']:
window.Element('_moduletext_').Update(visible = True)
How to hide the element using Radio button in pysimpleGUIqt?
回答1:
Enabling events for Radio Buttons was not implemented in PySimpleGUIQt yet. Just finished the code for it and tried your code against it.
You need to download the PySimpleGUIQt.py file on the project's GitHub site and place it in your application's folder.
来源:https://stackoverflow.com/questions/57007929/hiding-gui-elements-dynamically-using-radio-button-in-pysimpleguiqt