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() # 進入消息循環