From b453207c053584313feba05cdd9f07d073af44d5 Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Sun, 21 Mar 2021 09:59:44 -0400 Subject: [PATCH] Updated demo to confirm both the Exit button and "X" for closing window. --- DemoPrograms/Demo_Close_Attempted_Event.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/DemoPrograms/Demo_Close_Attempted_Event.py b/DemoPrograms/Demo_Close_Attempted_Event.py index f8e8be9c..6fbf22a8 100644 --- a/DemoPrograms/Demo_Close_Attempted_Event.py +++ b/DemoPrograms/Demo_Close_Attempted_Event.py @@ -1,5 +1,3 @@ -import PySimpleGUI as sg - """ Demo_Close_Attempted_Event @@ -9,6 +7,8 @@ import PySimpleGUI as sg Copyright 2021 PySimpleGUI Inc. """ +import PySimpleGUI as sg + layout = [[sg.Text('Close confirmation demo')], [sg.Text('Try closing window with the "X"')], [sg.Button('Go'), sg.Button('Exit')]] @@ -18,10 +18,7 @@ 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'): + if (event == sg.WINDOW_CLOSE_ATTEMPTED_EVENT or event == 'Exit') and sg.popup_yes_no('Do you really want to exit?') == 'Yes': break window.close()