Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I respond to window resize in PySimpleGUI

How can I get notified when the window is resized in PySimpleGUI?

I have a window that enables resize events, but I'm not finding a way to move the elements around when that resize occurs, so my window renames top left centered the same size when the window changes size.

Here is the basic code:

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
like image 461
nycynik Avatar asked Mar 01 '23 17:03

nycynik


1 Answers

Adding tkinter events to windows results in callback on change of windows size

import PySimpleGUI as sg


layout = [[sg.Button('Save')]]
window = sg.Window('Window Title',
                   layout,
                   default_element_size=(12, 1),
                   resizable=True,finalize=True)  # this is the chang
window.bind('<Configure>',"Event")

while True:
    event, values = window.read()
    if event == 'Save':
        print('clicked save')

    if event == "Event":
        print(window.size)

    if event == sg.WIN_CLOSED:
        print("I am done")
        break
like image 174
raghu Avatar answered Mar 15 '23 21:03

raghu