[Tkinter-discuss] Doing things on Tkinter termination

Michael Lange klappnase at web.de
Tue Jan 26 19:32:20 CET 2010


Hi Geoff,

On Tue, 26 Jan 2010 13:45:49 +0100
Geoff Bache <geoff.bache at gmail.com> wrote:

(...)
> Hi Michael,
> 
> Yes, I'd seen that, but it doesn't really fit the criteria of being
> independent of how
> it's closed. As far as I can see it will get called when the window's
> close button
> is pressed, and nothing else, so if the application itself calls
> "destroy", it won't actually get called.
> 
> Why doesn't it work to bind to "<Destroy>" like I did? That seemed
> the intuitive way to go, and it seems to work on Linux...
> 

I don't have a windows box at hand, so I cannot tell. On my linux box
it works, but when I bind the callback to the root tk window the
callback is triggered once for every child widget of root.
 
> (To explain some more, I'm still on my GUI testing effort from my
> previous question
> and am trying to handle window closures. So another potential solution
> would be if
> there was some way to simulate the actual window closure and
> programmatically trigger the window to be closed in the window
> manager. But I couldn't see a way to
> do that. So the next best thing for me was to use <Destroy> and
> exclude programmatic
> calls via interception.)
> 

Just a thought... IIRC last time I suggested to override mainloop(); if
this is an option you could put your "destroy" callback into the custom
mainloop() function, below self.tk.mainloop(n).

Regards

Michael



More information about the Tkinter-discuss mailing list