Tkinter / Threads: "Invalid command name"

Eric Brunel eric.brunel at N0SP4M.com
Fri Dec 19 04:12:39 EST 2003


Russell E. Owen wrote:
> In article <3fe1e985$0$11374$91cee783 at newsreader01.highway.telekom.at>,
>  Michael Schutte <m.schutte at aon.at> wrote:
> 
> 
>>...I want to write a server application; like telnet is a client. The user
>>should be able to bind() to a port and wait for a client. The written
>>and recieved data is stored in a Text widget, self.__text. The
>>accept()ing is done in a seperate thread (using the threading module),
>>in method self.__tryConnect().
>>But the seperate thread raises an exception at
>>  self.__text["state"]="normal" .
>>A part of the code:
> 
> 
> You should only deal with Tkinter from the main thread.
> 
> (That was most certainly true in the past. I'm not quite positive that 
> it is still supposed to be true, but I can assure you that it doesn't 
> work well on my system.)
> 
> I suggest you use a Lock or Queue or some other inter-thread 
> communication object to let the accept thread communicate with the rest 
> of the application.

I usually use the event_generate method with custom events on Tkinter widgets 
from secondary threads to report events to the main thread. This seems to work 
well on all platforms I've worked with (Linux, Windows, Solaris). The 
communication via a Lock or Queue is a bit less "natural", since you have to 
check regularly if a secondary thread tries to tell you something.

My €0.02. HTH.
-- 
- Eric Brunel <eric dot brunel at pragmadev dot com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com





More information about the Python-list mailing list