From bddfac2745af8c52e8825a5b83aa91b1ad11cb43 Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Mon, 4 Jan 2021 10:01:54 -0500 Subject: [PATCH] Close attempted demo --- DemoPrograms/Demo_Close_Attempted_Event.py | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 DemoPrograms/Demo_Close_Attempted_Event.py diff --git a/DemoPrograms/Demo_Close_Attempted_Event.py b/DemoPrograms/Demo_Close_Attempted_Event.py new file mode 100644 index 00000000..f8e8be9c --- /dev/null +++ b/DemoPrograms/Demo_Close_Attempted_Event.py @@ -0,0 +1,27 @@ +import PySimpleGUI as sg + +""" + Demo_Close_Attempted_Event + + Catches if a window close was tried by user (click "X") and confirms with a popup. + Requires PySimpleGUI 4.33.0 and later + + Copyright 2021 PySimpleGUI Inc. +""" + +layout = [[sg.Text('Close confirmation demo')], + [sg.Text('Try closing window with the "X"')], + [sg.Button('Go'), sg.Button('Exit')]] + +window = sg.Window('Window Title', layout, enable_close_attempted_event=True) + +while True: + event, values = window.read() + print(event, values) + if event == sg.WINDOW_CLOSE_ATTEMPTED_EVENT: + if sg.popup_yes_no('Do yuou really want to exit?') == 'Yes': + break + if event in (sg.WIN_CLOSED, 'Exit'): + break + +window.close()