【发布时间】:2021-10-02 17:28:48
【问题描述】:
我正在使用 PySimpleGUI,我希望能够单击一个按钮并将其显示在按钮下的文本上作为选择。选项是拆分或数据填充,但我无法弄清楚如何让事件处理程序更新文本或保存该选项,然后让代码根据该选项采取相应的行动。
到目前为止的代码看起来有点像这样
import PySimpleGUI as sg
layout = [
[sg.Text('Would you like to SPLIT or SPLIT AND DATA POPULATE')],
[sg.Button('Split', key='-SPLIT-'), sg.Button('Split and Populate', key ='-SANDP-')],
[sg.Text('Current Process:'), sg.Text('Process', key='-PROCESS-')]
]
window = sg.Window('Title', layout,size=(1000,500))
while True:
event, values = window.read()
if event is None or event == 'EXIT':
break
if event == '-SPLIT-':
window['-PROCESS-'].update(values("-SPLIT-"))
choice1 = window['-PROCESS-'].update("split")
if event == '-Split and Populate-':
window['-PROCESS-'].update("Split and Populate")
choice2 = window['-PROCESS-'].update("Split and Populate")
window.close()
#psuedo code following
if choice1
bla bla bla
if choice2
bla bla bla
我希望能够单击并将该按钮名称存储在选择 1 或选择 2 中,并且该按钮名称也出现在 gui 中,这可能吗?
【问题讨论】:
标签: python user-interface pysimplegui