Speeding up Simple Canvas Loop

Guido van Rossum guido at eric.cnri.reston.va.us
Sat May 8 01:25:58 EDT 1999


Randall Hopper <aa8vb at vislab.epa.gov> writes:

>     create_line = canvas.create_line
>     for line in lines:
>       create_line( line, width=0 )
> 
> Can canvas items for Tkinter canvases be created by a C extension (these
> vertices are actually coming from C code)?
> 
> The performance of this GUI app is acceptable except for the above loop,
> and it alone can literally take minutes (400-30k iterations).

If you look carefully in the Tkinter.py source at how much Python code
gets executed here you'll notice that it is a lot!  This is usually
okay, but is a performance hog when this happens to be your inner
loop.  I remember fixing a similar situation by bypassing most of that
Python code and calling the underlying Tcl/Tk command directly using
the canvas.tk.call() method.

--Guido van Rossum (home page: http://www.python.org/~guido/)




More information about the Python-list mailing list