Tkinter / Threads: "Invalid command name"

Michael Schutte m.schutte at aon.at
Thu Dec 18 18:53:38 CET 2003


I know, questions about Tkinter and threads have been answered very
often, but I want to ask anyway.
I am using Python 2.2 on a Linux (SuSE Linux 8.1) system.
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:

def go(self, portn):
	# Open the window and connect.

	# Bind self.__server to ("", portn), call listen(), ...

	# When everything's ok, start the accept()ing thread.
	thr=threading.Thread(target=self.__tryConnect)
	thr.start()

def __tryConnect(self):
	# Accept a connection
	success=1
	self.__text["state"]="normal"    # Here the exception is raised		
	self.__text.insert("end", "Waiting for connection... ")
	try: self.__client, addr=self.__server.accept()
	except: success=0
	if not success:
		self.__text.insert("end", "failed.\n")
	else:
		self.__text.insert("end", "ok, connected with %s.\n" % 					addr[0])
	self.__text["state"]="disabled"

But when I join() the thread, everything works as it should. Eventually
the self.__text reference is lost when __tryConnect() returns?
The exception is:

Exception in thread Thread-1:
Traceback (most recent call last):
	...
	File "...", line xx, in configure:
		self.tk.call((self.w, configure)
TclError: invalid command name ".123123123.12341234" ,

while ".123123123.12341234" is the text widgets identification.
Can anyone help me?

Michael Schutte <m.schutte at aon.at>




More information about the Python-list mailing list