Merge pull request #4086 from PySimpleGUI/Dev-latest

Updated demo to confirm both the Exit button and "X" for closing window.
This commit is contained in:
PySimpleGUI 2021-03-21 10:00:00 -04:00 committed by GitHub
commit f2755eac6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 6 deletions

View File

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