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:
commit
f2755eac6c
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue