Drawing Trees

Jeff Epler jepler at unpythonic.net
Tue May 21 15:53:09 EDT 2002


Apparently it is a performance problem in the Canvas widget to
repeatedly create and destroy objects---I had a program that emulated a
14-segment display (tcl/tk) and while it first ran with <<1%CPU, after
24 hours it would run with ~10%CPU.  At each iteration (about 1/second)
it would destroy the existing segments and create new ones.

When I changed to using the 'coords' command to either place a segment
onscreen or move it off the canvas to hide it, I got rid of this
problem.

The Pythonic translation would seem to be
    c = Canvas(...)
    # ... 
    item = c.create_....
    # ...
    c.coords(item, (100, 100)) # move item to (100, 100)

Of course you'll have to have something a little more complicated than I
did -- a pool of available items of each type, rather than a set maximum
number of lines ..

Jeff





More information about the Python-list mailing list