Hiding GUI elements dynamically using radio button in PySimpleGUIQt

让人想犯罪 __ 提交于 2020-04-11 07:03:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!