Python定义点击右上角关闭按钮事件(Python defines the event of clicking the close button in the upper right corner)
文章来自:https://www.cnblogs.com/iAmSoScArEd/p/11200029.html 爬虫、转载请注明出处。
import tkinter
import tkinter.messagebox
def callbackClose(): tkinter.messagebox.showwarning(title='警告', message='点击了关闭按钮') sys.exit(0) root = tkinter.Tk() root.title("点击关闭按钮事件") root.protocol("WM_DELETE_WINDOW", callbackClose) root.mainloop() # 进入消息循环