Detect when the “x” or close button is pressed

后端 未结 1 1714
轮回少年
轮回少年 2021-01-03 10:43

How would you know when the user pressed the \"x\" button on the close button in a python tkinter program and do an event?

相关标签:
1条回答
  • 2021-01-03 11:23

    You can override the closing protocol.

    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)
    
    0 讨论(0)
提交回复
热议问题