Using class structure with Python protocol delete window handlers Using class structure with Python protocol delete window handlers tkinter tkinter

Using class structure with Python protocol delete window handlers


Your Tracker class is a Frame.

self.protocol("WM_DELETE_WINDOW", self.handler) # is meant to be used with a Toplevel or root window.


I think it's going to be hard for us to tell you what is wrong with your class-based approach when you show us the original, working code instead of the non-working class-based code.

That being said, I can answer the question "Where exactly do I initialize the 'WM_DELETE_WINDOW' command?". You initialize it in the constructor of your application object.

class MyApp(Tk):    def __init__(self, *args, **kwargs):        Tk.__init__(self, *args, **kwargs)        ...        self.protocol("WM_DELETE_WINDOW", self.handler)