Jam*_*ala 3 python tkinter python-3.x
您如何知道用户何时在 python tkinter 程序中按下关闭按钮上的“x”按钮并执行事件?
您可以覆盖关闭协议。
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)
Run Code Online (Sandbox Code Playgroud)