Tkinter Protocols
Protocols can be translated as communication protocols, which within tkinter can be interpreted as communication protocols between the Windows Manager and the Application. tkinter also supports changing this communication protocol using the concept of binding.
Tkinter Protocols Example#1
Click the Close button in the upper left corner of the communication protocol content window to close the window, its name is WM_DELETE_WINDOW. this program will modify this protocol to add Messagebox after clicking this button, asking "End or Cancel", if you click the " OK" button to end this program.
from tkinter import *
from tkinter import messagebox
def callback():
print("The cross in the upper right corner of the window is clicked...")
result = messagebox.askokcancel("OK/CANCEL?","OK/CANCEL?")
if result:
root.destroy()
else:
# pass
return
root = Tk()
root.title("apidemos.com")
root.geometry("300x180")
root.protocol("WM_DELETE_WINDOW",callback) # Change protocol binding
root.mainloop()
Output: