【问题标题】:Hiding GUI elements dynamically using radio button in PySimpleGUIQt使用 PySimpleGUIQt 中的单选按钮动态隐藏 GUI 元素
【发布时间】:2019-07-12 13:26:05
【问题描述】:

我使用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 中使用单选按钮隐藏元素?

【问题讨论】:

  • 单选按钮通常有多个。不确定单个 Radio 的行为。单个复选框很好,但不是单选按钮。
  • 我认为您遇到了错误或未实现单选按钮 enable_events。我以为是,但可能不在 Qt 上。我会优先考虑并查看代码。
  • 太好了....这些需要在GitHub上问。
  • 这个页面确实有你在此处发布并链接的其他帖子的答案。消息似乎没有通过。

标签: python user-interface visible invisible pysimplegui


【解决方案1】:

单选按钮的启用事件尚未在 PySimpleGUIQt 中实现。刚刚完成了它的代码并尝试了你的代码。

您需要在project's GitHub site 上下载PySimpleGUIQt.py 文件并将其放在您的应用程序文件夹中。

【讨论】:

  • 感谢您更新代码。我在使用您的代码时遇到了错误,我在这里解释了:stackoverflow.com/questions/57034955/…
  • 我不建议在这里发布这类问题。将它们发布在项目的 GitHub 站点上。您将获得更快的支持,并且可以更轻松地发布您的代码和图像。
猜你喜欢
  • 1970-01-01
  • 2018-03-20
  • 2011-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-10
  • 1970-01-01
相关资源
最近更新 更多