New windows not appearing when after_idle tasks present

Steven Taschuk staschuk at telusplanet.net
Wed Feb 12 12:55:24 EST 2003


Allo!  I'm having trouble getting new windows to appear when
after_idle tasks are present.

I've searched the Google archives of c.l.py for previous posts on
this topic, but found nothing pertinent.  Feel free to tell me to
take the question to some Tcl or Tk list, or to RTFM (but please
wave vaguely in the direction of the right FM).  Though tolerably
familiar with Python, I am a newbie to Tk(inter).

Example:

	from Tkinter import *
	def spam():
		root.after_idle(spam)
	root = Tk()
	root.after_idle(spam)
	root.mainloop()

My objective here is to have a do-nothing idle task, spam, running
"in the background".  The problem is that, in the code as written,
the main window never appears.

I am surprised by this behaviour.  Even if the drawing of the new
window is deferred to its own idle task (rather than being done
immediately on receipt of an exposure event), I'd expect it to be
executed whether or not there are other idle tasks in the queue
re-registering themselves.

Variations and details:

If spam is never registered, the main window appears.

If spam runs, say, 10,000 times and then stops re-registering
itself, the main window appears, but only after all 10,000
iterations have been performed.

If spam is first registered with after(1, spam) instead of
after_idle(), the main window appears (before, I think, spam is
executed for the first time).  Similarly if it re-registers itself
with after() instead of after_idle().

The same problem (apparently) arises in callback code which
creates a new Toplevel and a self-re-registering idle task.

In case I'm not just misunderstanding the Tk control flow model:
my machine runs Python 2.2.2, Tk/Tcl 8.4.1, Fvwm 2.4.3, and
XFree86 4.1.0, all on a roll-your-own Linux.

-- 
Steven Taschuk           |   ,\
staschuk at telusplanet.net | }<__`O=
                         |  '  "     Pleiosaur





More information about the Python-list mailing list