PysimpleGui窗口关闭事件

文章展示了一个使用PySimpleGUI库创建的代码示例,当用户尝试点击窗口关闭按钮(X)时,会弹出一个确认对话框,要求用户进行二次确认是否真的要退出程序。这个功能需要PySimpleGUI4.33.0及以上版本支持。
摘要由CSDN通过智能技术生成

点击窗口关闭按钮,需要进行二次确认,代码如下:

"""
    Demo_Close_Attempted_Event

    Catches if a window close was tried by user (click "X") and confirms with a popup.
    Requires PySimpleGUI 4.33.0 and later

    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')]]

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 or event == 'Exit') and sg.popup_yes_no('Do you really want to exit?') == 'Yes':
        break

window.close()

转发请备注出处!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值