简体   繁体   中英

How do I enable and react to the Maximize button when using PySimpleGUI

How do I enable the maximize button, and how do I react to it?

I think the way to react to it is to use the maximize() and normal() functions on the window object, like so:

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

The Maximize button is not enabled in the window bar, so I can't click it and try to find the event, I feel like there is something I need to do to tell the window that there is a callback for maximizing the window.

I have a similar question to this question , but not using TK and instead with PySimpleGUI.

To enable the window to be resizable, you just need to add resizable to the window declaration.

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

I found the solution!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM