我使用了 this post 中的以下方法隐藏 GUI 元素效果很好:
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)
这里的问题是,如果我用单选按钮替换复选框,那么相同的代码不会动态隐藏 gui 元素。下面是带有单选按钮的代码:
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)
如何在 pysimpleGUIqt 中使用单选按钮隐藏元素?
最佳答案
PySimpleGUIQt 中尚未实现启用单选按钮事件。刚刚完成了它的代码,并尝试了你的代码。
您需要下载PySimpleGUIQt.py文件 project's GitHub site并将其放入您的应用程序的文件夹中。
关于python - 使用 PySimpleGUIQt 中的单选按钮动态隐藏 GUI 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57007929/