From 4ff123583cb0f5467811cc45fc740093d1c17d23 Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Sun, 5 Jun 2022 14:29:08 -0400 Subject: [PATCH] New Demo Program to show how the new enable_window_config_events parameter works --- DemoPrograms/Demo_Window_Config_Events.py | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 DemoPrograms/Demo_Window_Config_Events.py diff --git a/DemoPrograms/Demo_Window_Config_Events.py b/DemoPrograms/Demo_Window_Config_Events.py new file mode 100644 index 00000000..4df13a32 --- /dev/null +++ b/DemoPrograms/Demo_Window_Config_Events.py @@ -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()