[Image-SIG] ImageTk and threading - warning

kevin at cazabon.com kevin at cazabon.com
Mon Jun 19 22:31:43 CEST 2006

I'm not sure how many people out there are doing multi-threading and Tk, but 
I just wanted to post a warning after spending a few months trying to track 
down a nasty (and very rare) crashing bug in one of my programs.  I wish I 
had been more skeptical from the start.  :)

I know that Tkinter isn't thread safe - so only use one thread to touch any 
Tkinter objects or their properties.  However, I didn't think twice about 
creating an ImageTk.PhotoImage(of_my_image) in a secondary thread, and 
passing it to the GUI thread for display.  For some reason, doing this works 
in 99.99% of the time, but occasionally crashes with an access violation 
error, pointing to the Tk DLL.

So - until Tk is thread-safe (I'm not holding my breath, it wouldn't be a 
trivial task), just use the same thread that creates the Tk widgets to 
convert your images to PhotoImages.


More information about the Image-SIG mailing list