Updated demo to confirm both the Exit button and "X" for closing window.

This commit is contained in:
PySimpleGUI 2021-03-21 09:59:44 -04:00
parent 66ff5da9c9
commit b453207c05
1 changed files with 3 additions and 6 deletions

View File

@ -1,5 +1,3 @@
import PySimpleGUI as sg
""" """
Demo_Close_Attempted_Event Demo_Close_Attempted_Event
@ -9,6 +7,8 @@ import PySimpleGUI as sg
Copyright 2021 PySimpleGUI Inc. Copyright 2021 PySimpleGUI Inc.
""" """
import PySimpleGUI as sg
layout = [[sg.Text('Close confirmation demo')], layout = [[sg.Text('Close confirmation demo')],
[sg.Text('Try closing window with the "X"')], [sg.Text('Try closing window with the "X"')],
[sg.Button('Go'), sg.Button('Exit')]] [sg.Button('Go'), sg.Button('Exit')]]
@ -18,10 +18,7 @@ window = sg.Window('Window Title', layout, enable_close_attempted_event=True)
while True: while True:
event, values = window.read() event, values = window.read()
print(event, values) print(event, values)
if event == sg.WINDOW_CLOSE_ATTEMPTED_EVENT: if (event == sg.WINDOW_CLOSE_ATTEMPTED_EVENT or event == 'Exit') and sg.popup_yes_no('Do you really want to exit?') == 'Yes':
if sg.popup_yes_no('Do yuou really want to exit?') == 'Yes':
break
if event in (sg.WIN_CLOSED, 'Exit'):
break break
window.close() window.close()