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()