Fab*_*bix 0 python user-interface tkinter pysimplegui
我正在尝试使用 PySimpleGUI 制作 GUI 应用程序。
单击“确认”按钮后,我需要在窗口上显示不同的按钮。
我在第一个布局中使用带有“可见性 false”的按钮来完成此操作,当我单击“确认”按钮时,脚本会更改最初不可见的按钮的可见性。
问题是按钮是可见的,但它们不在一行,而是在同一列。
这是第一个窗口:
更新后的窗口应如下所示:
更新后的窗口如下所示:
这是我的代码:
import PySimpleGUI as sg
sg.theme('DarkAmber')
layout = [
[sg.Text('\n\nText sample', key = '_text_', visible = True)],
[sg.Text('Second sample: ', key = '_text2_'), sg.InputText(key='_IN_', size=(10, 1))],
[sg.Text()],
[sg.Button('Confirm', key = '_CONFIRM_', visible=True),
sg.Button('1', key ='_1_', visible=False),
sg.Button('2', key = '_2_', visible=False),
sg.Button('3', key = '_3_', visible=False),
sg.Cancel('Exit', key = '_EXIT_')],
]
window = sg.Window('Window', layout)
while True:
event, values = window.read()
if event in (sg.WIN_CLOSED, '_EXIT_'):
break
elif '_CONFIRM_' in event:
window['_text_'].Update(visible = False)
window['_text2_'].Update('Second text updated')
window['_EXIT_'].Update(visible = False)
window['_CONFIRM_'].Update(visible = False)
window['_1_'].Update(visible = True)
window['_2_'].Update(visible = True)
window['_3_'].Update(visible = True)
window['_EXIT_'].Update(visible = True)
Run Code Online (Sandbox Code Playgroud)
您知道如何正确显示同一行中的按钮吗?谢谢!
sg.pin是提供到布局中的元素,以便当它再次不可见和可见时,它将位于正确的位置。否则它将被放置在其包含窗口/列的末尾。替换sg.Button(...)为sg.pin(sg.button(...))布局时。
import PySimpleGUI as sg
sg.theme('DarkAmber')
layout = [
[sg.pin(sg.Text('\n\nText sample', key = '_text_', visible = True))],
[sg.Text('Second sample: ', key = '_text2_'), sg.InputText(key='_IN_', size=(10, 1))],
[sg.Text()],
[sg.Button('Confirm', key = '_CONFIRM_', visible=True),
sg.pin(sg.Button('1', key = '_1_', visible=False)),
sg.pin(sg.Button('2', key = '_2_', visible=False)),
sg.pin(sg.Button('3', key = '_3_', visible=False)),
sg.Cancel('Exit', key = '_EXIT_')],
]
window = sg.Window('Window', layout)
while True:
event, values = window.read()
if event in (sg.WIN_CLOSED, '_EXIT_'):
break
elif '_CONFIRM_' in event:
window['_text_'].Update(visible = False)
window['_text2_'].Update('Second text updated')
window['_EXIT_'].Update(visible = False)
window['_CONFIRM_'].Update(visible = False)
window['_1_'].Update(visible = True)
window['_2_'].Update(visible = True)
window['_3_'].Update(visible = True)
window['_EXIT_'].Update(visible = True)
window.close()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13026 次 |
| 最近记录: |