检测“x"何时出现或关闭按钮被按下 [英] Detect when the "x" or close button is pressed
本文介绍了检测“x"何时出现或关闭按钮被按下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您如何知道用户何时在 python tkinter 程序中按下关闭按钮上的x"按钮并执行事件?
How would you know when the user pressed the "x" button on the close button in a python tkinter program and do an event?
推荐答案
您可以覆盖关闭协议.
def on_close():
#custom close options, here's one example:
close = messagebox.askokcancel("Close", "Would you like to close the program?")
if close:
root.destroy()
root.protocol("WM_DELETE_WINDOW", on_close)
这篇关于检测“x"何时出现或关闭按钮被按下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文