Multithreaded tkinter GUI application exception handling

Michael Zhang jianqiz at
Tue Oct 12 16:14:57 CEST 2004

My project uses Python-2.3.4 + Tkinter + PIL-1.1.4 to retrieve images 
from server and display those images.

I created a thread (also a separate toplevel window) for displaying 
images and another thread for recording the frame rates (using a 
progress bar for visulization). The whole application worked very well 
once it received image data from the socket.

The problem is when I tried to close that display window (click on the 
standard "X" button on the right-upper corner), I got this exception:

Exception in thread Thread-1:
Traceback (most recent call last):
   File "/usr/local/lib/python2.3/", line 436, in __bootstrap
   File "", line 188, in run
   File "", line 238, in __init__
     self.canvas.create_image(0, 0, image=self.image, anchor=NW)
   File "/usr/local/lib/python2.3/lib-tk/", line 2060, in 
     return self._create('image', args, kw)
   File "/usr/local/lib/python2.3/lib-tk/", line 2049, in _create
     return getint(
TclError: invalid command name ".1080883980.1080884908"

Then after I closed the main windows, I got another exception:

Exception in thread Thread-2:
Traceback (most recent call last):
   File "/usr/local/lib/python2.3/", line 436, in __bootstrap
   File "", line 198, in run
   File "/home/michael/usyd/soft3700/py/realtime/", line 
73, in updateProgress
   File "/home/michael/usyd/soft3700/py/realtime/", line 
91, in update
     float(value) / self.max * self.width, self.height)
   File "/usr/local/lib/python2.3/lib-tk/", line 2039, in coords
TclError: invalid command name 

Why is the "TclError"? How can I handle those exceptions and exit the 
applicaton gracefully?

Could someone help me out about those thread stuff? Thanks!


More information about the Python-list mailing list