[Tkinter-discuss] Persuading after_idle callback to only get called when the window is mapped

Geoff Bache geoff.bache at gmail.com
Fri Jan 15 21:13:22 CET 2010


Hi again Michael,

>
> Hmm, from your previous posts I thought you would just do the call to
> root.after_idle(self.replayEvents) right before root.mainloop() ?
> If so, why not do
>
>    root.deiconify()
>    root.update()
>    root.after_idle(self.replayEvents)
>    root.mainloop()

The problem is that I have to break in by intercepting something as
the application code doesn't know I exist :)

At the moment I'm intercepting the construction of Tk() which is
guaranteed to happen and is easy to intercept. Intercepting mainloop
is more problematic because all widgets have a mainloop method and
there's no knowing which one the application will call.

>
> I don't think there is any risk in using update() like this. I am
> afraid I did not understand you properly though, and what you are trying
> is more complex than I thought. I actually don't have any experience
> with gui testing tools :)
> Another idea, which looks a little hackish, but maybe does the trick as
> well, is to add a test if the window is visible to the replayEvents()
> method and if not call it again after 100 ms or so, like:
>
>    def replayEvents(self):
>        if root.winfo_ismapped():
>            # do things....
>        else:
>            root.after(100, self.replayEvents)
>
> Really not nice, but simple (and maybe effective?).

Yes, I can maybe make it work with sleeps like this if I have to. I
also haven't yet tried your solution of using "<Map>" events, which
might be worth a go.

Thanks for the suggestions anyway.

Regards,
Geoff


More information about the Tkinter-discuss mailing list