[Tkinter-discuss] Main loop / Scheduling
Fredrik Lundh
fredrik at pythonware.com
Thu Apr 10 21:26:24 CEST 2008
Alec Solway wrote:
> If so, then why does the following work? What actually calls bar() below?
>
> foo = Tk()
> def bar():
> print "bar"
> foo.after(1000, bar)
> # Drop back to prompt with 'after#0' response
drop back to prompt? are you running this in interactive mode?
the CPython interactive mode provides a "background event loop" that
keeps Tkinter's event loop running. this is useful when tinkering when
UI stuff from the command line, but is nothing you can rely on for code
that you run outside the interactive mode.
(you cannot rely on it in interactive mode either; it only works on Unix
if you're using the readline library, and only works on Windows if you
don't type anything into the window. as soon as you touch the keyboard,
the event loop is terminate).
to solve your problem, use an ordinary Python thread, and use a Queue
object to pass results from the background thread to the main Tkinter
thread.
</F>
More information about the Tkinter-discuss
mailing list