[Tkinter-discuss] Persuading after_idle callback to only get called when the window is mapped
Michael Lange
klappnase at web.de
Wed Jan 13 23:48:08 CET 2010
Hi Geoff,
On Wed, 13 Jan 2010 22:41:55 +0100
Geoff Bache <geoff.bache at gmail.com> wrote:
(...)
>
> Hi Michael,
>
> Thanks for your detailed reply. I feel also that there should be a
> simpler solution and I can't say I *want* to use threads exactly. What
> I think you're missing above is that a GUI testing tool is supposed to
> deal with an arbitrary application under test so I don't have any
> control over the widgets and how they're packed. That also makes it
> difficult to call root.update() because I don't know when the
> application would be ready for me to do so.
>
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()
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?).
Regards
Michael
> In any case, the documentation for update() is as follows:
>
> "This method forces the updating of the display. It should be used
> only if you know what you're doing, since it can lead to unpredictable
> behavior or looping. It should never be called from an event callback
> or a function that is called from an event callback."
>
> makes it sound just about as risky as what I'm doing at the moment...
> especially as I can't really claim I know what I'm doing having looked
> at tkinter for the first time less than a week ago :)
>
> Regards,
> Geoff
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
More information about the Tkinter-discuss
mailing list