Creating frames in threads
Eric Brunel
eric_brunel at despammed.com
Thu Mar 11 06:33:43 EST 2004
Bob Greschke wrote:
> I have a program that creates one or more frames with
>
> TF = TopLevel(Root)
>
> talks to some equipment, calculates some stuff, draws a graph on a canvas in
> the frame, then exits. The frame/s goes with the thread and disappears when
> the thread is finished -- which I guess makes sense. Is there a way to keep
> those frames around after the thread is gone?
Do you mean that the "frame" (I'd call it a window, but nevermind...) is created
by the thread? If it is, please be aware that there are some issues regarding
Tkinter and threads. To keep it simple, it is better to leave all Tkinter
related stuff in one thread (the main thread is a good candidate) and to
communicate via this thread via Tkinter events using the event_generate method
and Queue(s). You're for the moment in a situation where accessing Tkinter from
multiple threads seems to work, but you may get stuck in the future.
For your particular problem, I'd create the frames outside of the thread and use
event_generate and a Queue to pass the information to display to the main
thread, which would actually display it on the Canvas. This will make the design
heavier, but you'll be sure that you won't have any problem in the future.
HTH
--
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
More information about the Python-list
mailing list