Merge pull request #5571 from PySimpleGUI/Dev-latest

New Demo Program to show how the new enable_window_config_events para…
This commit is contained in:
PySimpleGUI 2022-06-05 14:29:20 -04:00 committed by GitHub
commit d6a772a9e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,34 @@
import PySimpleGUI as sg
"""
Demo Window Config Events
The Window object has a parameter enable_window_config_events that when set to True will
cause sg.WINDOW_CONFIG_EVENT events to be generated when the window is moved or resized.
Note that if you move the window using the Titlebar supplied by the operating system, then you
will only get an event at the end of the window being moved. If you want to receive numerous
events during the movement, then you can achieve this using a grab_anywhere setting either
at the window level or on a single element as shown in this demo.
Copyright 2022 PySimpleGUI
"""
layout = [ [sg.Text('Demonstration of the enable_window_config_events')],
[sg.Text('Grab me HERE for continuous location changed events', grab=True, text_color=sg.theme_background_color(), background_color=sg.theme_text_color())],
[sg.Text(key='-OUT-', font='_18')],
[sg.VPush()],
[sg.Button('Go'), sg.Button('Exit'), sg.Sizegrip()] ]
window = sg.Window('Window Title', layout, resizable=True, enable_window_config_events=True, finalize=True)
window.set_min_size(window.current_size_accurate())
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Exit':
break
if event == sg.WINDOW_CONFIG_EVENT:
window['-OUT-'].update(f'Size: {window.current_size_accurate()}\nLocation:{window.current_location()}')
window.close()