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:
JavaScript
x
19
19
1
import PySimpleGUI as sg
2
3
layout = [[sg.Button('Save')]]
4
window = sg.Window('Window Title',
5
layout,
6
default_element_size=(12, 1),
7
resizable=True) # this is the change
8
9
while True:
10
event, values = window.read()
11
if event == 'Save':
12
print('clicked save')
13
14
if event == sg.WIN_MAXIMIZED: # I just made this up, and it does not work. :)
15
window.maximize()
16
17
if event == sg.WIN_CLOSED:
18
break
19
Advertisement
Answer
You need to bind "<Configure>"
event to check zoomed event.
JavaScript
1
20
20
1
import PySimpleGUI as sg
2
3
layout = [[sg.Text('Window normal', size=(30, 1), key='Status')]]
4
window = sg.Window('Title', layout, resizable=True, finalize=True)
5
window.bind('<Configure>', "Configure")
6
status = window['Status']
7
8
while True:
9
10
event, values = window.read()
11
if event == sg.WINDOW_CLOSED:
12
break
13
elif event == 'Configure':
14
if window.TKroot.state() == 'zoomed':
15
status.update(value='Window zoomed and maximized !')
16
else:
17
status.update(value='Window normal')
18
19
window.close()
20