Help on multithreading and Tkinter; Linux vs Windows
Eric Brunel
eric_brunel at despammed.com
Mon May 24 04:22:32 EDT 2004
corrado wrote:
> Hello
>
> I have an application running several thread to display some financial
> data;
> basically I have a thread displaying HTML tables by means of Tkhtml,
> another implementing a scrolling ticker based on a Text widget with
> embedded windows and a thread running the Tkinter mainloop plus
> several other thread dealing with the scheduling of the contents and
> the acquisition of data but not using graphic widgets.
> I run the same code on Linux and Windows; I have no problems on Linux
> while on Windows everything get stucked when I tried to scroll the
> ticker, it looks like I'm blocked in mywidget.xview(SCROLL,1,UNITS);
> at this time the graphic of the application freezes while all the rest
> goes on running.
Like many other GUI toolkits, it seems that Tkinter doesn't like to be called
from several threads in the same application. The fact that it works on Linux is
what is suprising to me: I already tried to do a similar thing on Linux and
finally gave up, because I experienced many lock-ups like you do.
The solution is always the same: use only one thread to manage the GUI,
preferably the main one, and use a combination of Tkinter GUI events posted via
event_generate and Queue's to pass information from secondary threads to the
GUI. It messes up the code a bit, but it's the only way we've found to avoid the
lock-up's you're experiencing.
[snip]
> Is there anyone who can help me? I've already tried the
> Tkinter-discuss mailing list but I got no answer.
> I supposed Tkinter worked the same way under Windows and Linux but it
> does not look like it's so; is there any paper explaining the
> differences between the behaviour on the two operating systems? For
> instance on Windows I also had problem with iconify and with the
> button highlight, which is Windows standard whatever setting you try.
Try the tcl/tk documentation at http://www.tcl.tk/man ; it of course describes
the tcl commands corresponding to the Tkinter classes and methods, but has much
more details about the differences between the supported platforms than any
Tkinter documentation I know. But you're touching quite a deep problem here: the
mix of GUI and threads is a tough issue, and the problems you experience may
depend not only on tk or Tkinter, but also on how Python manages threads and how
the underlying system supports them. I fear your best source of info on this
matter will be newsgroups like this one...
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