Problems with Tkinter and threads

Paul Rubin http
Mon Jul 17 07:12:23 EDT 2006


"Claus Tondering" <claus.tondering at gmail.com> writes:
> The TCP communication takes place in a separate thread. When I receive
> data, I generate an event in the Python application thus:
> 
>     app.event_generate("<<myevent1>>")

I think all bets are off when you do that.  Tkinter is simply not
thread safe and generating events from another thread can trigger race
conditions and who knows.  You need to self-generate events in the
gui thread with (e.g.) Tk.after, and have those events check for news
from the TCP thread.  You could do that with a semaphore, or more
pythonically with a Queue.



More information about the Python-list mailing list