Take the 2-minute tour ×

I use a Tkinter window to visualize some output of my programm. The window is threaded (see basic structure below) and basically it works quite fine. So far, I only have trouble closing the window. When I clicke the "X" button for closing the window it works.

However, when I call the Monitor.close() method from the main programm that starts the monitor thread, the window just freezes (e.g., it doesn't react on clicking the "X" button) and the thread monitor keeps running. Thus, the main program does not exit.

So, at the moment, I also have to close first the window "manually" by clicking the closing button and then the main program. Not a big issue, but it would be great, if the main program could close the window by itself. Any hints?

Thanks and best regards,


class Monitor(threading.Thread):

    def __init__(self):

    def close(self):

    def run(self):
        self.root.protocol("WM_DELETE_WINDOW", self.close)
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Python Threading and Tk(inter) used in this way do not mix well, as they violate the Tcl/Tk threading model of using Tk just from one thread.

It works great with message passing though, just not with direct calls from a thread. So you need to add some message passing via Queue to this.

Have a look at http://effbot.org/zone/tkinter-threads.htm for an example.

share|improve this answer
Thanks for you answer, I will ee to that! It's just interesting (to me) that everything else works quite fine, e.g., calling the a draw() method from the main program. –  Christian Aug 11 '11 at 11:10
It is as usual with threading issues. Things seem to work just fine, until they stop doing it because you hit some timing issue, race condition, data corruption or deadlock. Tcl/Tk has quite a nice threading model (message passing based, without shared state or a GIL), while Python uses a different model with shared state and locks like the GIL everywhere. Mixing those two can work, but sometimes does not. –  schlenk Aug 11 '11 at 20:49
Thanks for elaborating in that! –  Christian Aug 12 '11 at 7:46
mtTkinter - A thread-safe version of Tkinter: tkinter.unpythonic.net/wiki/mtTkinter –  Gonzo Oct 18 '12 at 15:35
add comment

Your Answer


