Multithreading tkinter question
Oleg Paraschenko
olepar at gmail.com
Fri Dec 17 02:21:21 EST 2004
Hello John,
> Mark,
>
> I tried your code snippet with Python 2.3.4. Worked fine. Only
problem was
> that the program fell off the end and terminated before the second
thread
> could open the Tkinter window. So I added these lines at the end to
make the
> main thread wait:-
>
> from msvcrt import kbhit, getch
> print "\n\nPress key to end"
> while not kbhit(): pass
> getch()
And I added
print "\n\nPress key to end"
l = sys.stdin.readline()
> Both your Hello and Quit buttons worked.
In my case "Hello" works and "Quit" doesn't (GUI stays frozen).
Linux, Python 2.3.3, pygtk-0.6.9.
> ...
>
> It is not optimal in that 'otherThread' runs continuously even when
the
> label is not being updated. What a waste of cpu cycles! This shows up
in
> that other windows apps slow right down. What is needed is a comms
method
> between threads that causes a thread to block while it's waiting for
data
> rather than my continuous polling approach. Would a Queue help here?
>
Yes, it should help. A time ago I tried to write a tkinter
application,
and my test code is available:
A complete Python Tkinter sample application for a long operation
http://uucode.com/texts/pylongopgui/pyguiapp.html
Maybe you find it interesting.
--
Oleg
More information about the Python-list
mailing list