使用 PySimpleGUI 时如何启用最大化按钮并对其做出反应
How do I enable and react to the Maximize button when using PySimpleGUI
如何启用最大化按钮,我该如何应对?
我认为应对它的方法是在 window 对象上使用 maximize()
和 normal()
函数,如下所示:
import PySimpleGUI as sg
layout = [[sg.Button('Save')]]
window = sg.Window('Window Title', layout,
default_element_size=(12, 1))
while True:
event, values = window.read()
if event == 'Save':
print('clicked save')
if event == sg.WIN_MAXIMIZED: # I just made this up, and it does not work. :)
window.maximize()
if event == sg.WIN_CLOSED:
break
最大化按钮在 window 栏中未启用,所以我无法单击它并尝试查找事件,我觉得我需要做一些事情来告诉 window 有一个用于最大化 window.
的回调
我有一个与 类似的问题,但不是使用 TK,而是使用 PySimpleGUI。
要使 window 可以调整大小,您只需将 resizable
添加到 window 声明。
import PySimpleGUI as sg
layout = [[sg.Button('Save')]]
window = sg.Window('Window Title',
layout,
default_element_size=(12, 1),
resizable=True) # this is the change
while True:
event, values = window.read()
if event == 'Save':
print('clicked save')
if event == sg.WIN_MAXIMIZED: # I just made this up, and it does not work. :)
window.maximize()
if event == sg.WIN_CLOSED:
break
我找到了解决方案!
如何启用最大化按钮,我该如何应对?
我认为应对它的方法是在 window 对象上使用 maximize()
和 normal()
函数,如下所示:
import PySimpleGUI as sg
layout = [[sg.Button('Save')]]
window = sg.Window('Window Title', layout,
default_element_size=(12, 1))
while True:
event, values = window.read()
if event == 'Save':
print('clicked save')
if event == sg.WIN_MAXIMIZED: # I just made this up, and it does not work. :)
window.maximize()
if event == sg.WIN_CLOSED:
break
最大化按钮在 window 栏中未启用,所以我无法单击它并尝试查找事件,我觉得我需要做一些事情来告诉 window 有一个用于最大化 window.
的回调我有一个与
要使 window 可以调整大小,您只需将 resizable
添加到 window 声明。
import PySimpleGUI as sg
layout = [[sg.Button('Save')]]
window = sg.Window('Window Title',
layout,
default_element_size=(12, 1),
resizable=True) # this is the change
while True:
event, values = window.read()
if event == 'Save':
print('clicked save')
if event == sg.WIN_MAXIMIZED: # I just made this up, and it does not work. :)
window.maximize()
if event == sg.WIN_CLOSED:
break
我找到了解决方案!