改变关闭窗口的默认行为
python 2.x
from Tkinter import * import tkMessageBox app = Tk() app.title("HelloWorld") app.geometry('250x100+200+100') def shutdown(): if tkMessageBox.askokcancel(title = 'Are you sure?', message = 'Do you really want to quit?'): app.destroy() app.protocol("WM_DELETE_WINDOW", shutdown) app.mainloop()