[Tkinter-discuss] Doing things on Tkinter termination

Geoff Bache geoff.bache at gmail.com
Tue Jan 26 20:00:56 CET 2010


Hi again Michael,

>> 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.

Yes, that's true. It's easy to fix that though of course.

Maybe I should report this as a Python bug? It presumably shouldn't be
possible to crash Python like this just by writing Python code.

>
>> (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).

Yes, maybe something like that could work. It feels a bit convoluted
but I guess there aren't too many other options available that I can
see.

Thanks,
Geoff


More information about the Tkinter-discuss mailing list