【问题标题】:PySimpleGUI Textbox output for information after choosing radiobutton选择单选按钮后的 PySimpleGUI 文本框输出信息
【发布时间】:2020-12-01 01:49:53
【问题描述】:

所以我现在要做的是,如果我单击其中一个单选按钮,则有关该方法的一些信息应自动显示在 GUI 中,但我似乎无法正确处理。 我想也许我可以通过使用 if 语句来完成它,但没有任何反应。

import PySimpleGUI as sg

# List for Radiobuttons
radio_choices = ["Method 1", "Method 2", "Method 3", "Method 4"]

layout = [[sg.Text("Choose Method")],
          *[[sg.Radio(text, 1), ] for text in radio_choices],
          [sg.Button("Start"), sg.Button("Stop"), sg.Button("Exit")]


          ]

window = sg.Window("Choose Method", layout, size=(350, 350))

while True:
    event, values = window.Read()

    
    if event == "Exit" or event == sg.WIN_CLOSED:
        break

    if event == radio_choices[0]:
        sg.Text("Method 1 description")
window.close()

【问题讨论】:

    标签: python user-interface radio-button pysimplegui


    【解决方案1】:

    试试这个:

    import PySimpleGUI as sg
    
    # List for Radiobuttons
    radio_choices = ["Method 1", "Method 2", "Method 3", "Method 4"]
    
    layout = [[sg.Text("Choose Method")],
              *[[sg.Radio(text, 1),sg.Text('this is ' + text ,key=text, visible=False) ] for text in radio_choices],
              [sg.Button("Start"), sg.Button("Stop"), sg.Button("Exit")]
    
    
              ]
    
    window = sg.Window("Choose Method", layout, size=(350, 350))
    
    while True:
        event, values = window.Read()
    
        print(event, values)
        if event == "Exit" or event == sg.WIN_CLOSED:
            break
    
        if event == 'Start':
            for k,value in values.items():
                if value == True:
                    window[radio_choices[k]].update(visible=True)
                else : 
                    window[radio_choices[k]].update(visible=False)
    window.close()
    

    【讨论】:

    • 谢谢你,但这不是我的想法。想法也是在该方法的作用中添加描述。在布局中,我添加了另一个名为“sg.Button("Information") 的按钮来输出文本。您认为可以将输出文本放在特定区域而不是单选按钮旁边吗?
    猜你喜欢
    • 2012-10-01
    • 1970-01-01
    • 2020-06-25
    • 2015-11-26
    • 2013-06-28
    • 2016-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多