[Tkinter-discuss] Tkinter, threads? memory?

Michael M Haimes mhaimes at MIT.EDU
Wed Sep 20 18:27:47 CEST 2006

Hello Tkinter community, I'm a relatively experienced Python/Tk programmer
having worked on multiple larger scale projects now, and I'm having two issues
with Tkinter:

Linux implementations of Python/Tkinter (the most current) seem to exhibit the
problem, but not Sun/Solaris or Windows.

Essentially, I can't animate objects on a canvas without leaking memory at about
1Mb/s . I've tried 4 different methods, either deleting and redrawing objects,
or just moving objects, and either using Tk tags to label and operate the
objects, or storing their IDs in my program and operating with them that way. I
can't think of any other way to do this, and I basically need to. I would try
the WCK to make my own, but the idea is to have the software run on a base
install of Python.

The link to the four example test scripts I wrote up is here:

The Mac OS X implementation of Python seems to exhibit this problem, and no
other systems.

This problem is related to the above, namely, on the Mac animation seems to be
totally broken. Whenever Tk is running its event loop, it stops all other
python threads from processing and sits and waits for input. So my example code
below runs a counter in a background thread which increments the number Tk has
displayed. On Windows/Linux, it just counts up until you press exit. On the
Mac, it will sit there and freeze if you aren't inputting anything, but as soon
as you wave the mouse around or start typing it'll continue to increment;
whereas on Windows and Linux, the counter just counts up no matter what you are
inputting. I know this could be done without two separate threads, but the real
program that this is modelling an issue I'm having needs Tk to be in its event
loop, so that is not an option.

Test code as follows:
import Tkinter
import thread
import sys

app = Tkinter.Tk()
text = Tkinter.StringVar()
Tkinter.Label(app, textvariable = text).pack()
def looper():
        count = 0
        while 1:
thread.start_new_thread(looper, ())
Tkinter.Button(app, text="exit", command = sys.exit).pack()


If anyone has any hints or suggestions for workarounds for either of the above
problems, it would be much appreciated. Or if you just run any of the test
programs on your systems and get different results than I predicted for you,
tell me some things about your system and what happened.

-Mike Haimes

More information about the Tkinter-discuss mailing list