使用PySimpleGUIQt中的单选按钮动态隐藏GUI元素 [英] Hiding GUI elements dynamically using radio button in PySimpleGUIQt

查看:838
本文介绍了使用PySimpleGUIQt中的单选按钮动态隐藏GUI元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这篇文章中使用了以下方法来隐藏非常有效的GUI元素:

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)

这里的问题是,如果我将复选框替换为单选按钮,则相同的代码不会动态隐藏gui元素.下面是带有单选按钮的代码:

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)

如何使用pysimpleGUIqt中的单选"按钮隐藏元素?

How to hide the element using Radio button in pysimpleGUIqt?

推荐答案

单选按钮的启用事件尚未在PySimpleGUIQt中实现.刚刚完成了代码,然后尝试对它进行编码.

Enabling events for Radio Buttons was not implemented in PySimpleGUIQt yet. Just finished the code for it and tried your code against it.

您需要下载 PySimpleGUIQt.py 文件在项目的GitHub网站上,并将其放置在应用程序的文件夹中.

You need to download the PySimpleGUIQt.py file on the project's GitHub site and place it in your application's folder.

这篇关于使用PySimpleGUIQt中的单选按钮动态隐藏GUI元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆