Capturing the protocol event isnt enough

Your code captures the protocol event and redefines its behavior. But, what about the behavior that used to execute by default?

Take a look at this small example program, which redefines the close-box protocol to check with the user before actually destroying the window:

from tkinter import *

from tkinter.messagebox import askokcancel app = Tk()

app.title("Capturing Events") app.geometry('250x100+200+200')

if askokcancel(title = 'Are "you .sure?', message = 'Do you really want to quit?'): app.destroy()

app.protocol("WM_DELETE_WINDOW", shutdown) app.mainloop()

Clicking on the close box runs the "shutdownO" function, which then^ displays an AskOkCancel dialog- ^

If you click OK, the GUI is destroyed (which has the effect of closing the window).

Add the app . destroy () line of code to the end of your shutdown () function and see if it makes any difference.

Was this article helpful?

0 0

Post a comment