Running a Tkinter form in a separate thread

Tkinter isn’t thread safe, and the general consensus is that Tkinter doesn’t work in a non-main thread. If you rewrite your code so that Tkinter runs in the main thread, you can have your workers run in other threads.

The main caveat is that the workers cannot interact with the Tkinter widgets. They will have to write data to a queue, and your main GUI thread will have to poll that queue.

If all you’re doing is showing images, you probably don’t need threading at all. Threading is only useful when you have a long running process that would otherwise block the GUI. Tkinter can easily handle hundreds of images and windows without breaking a sweat.

Leave a Comment