Speeding up Simple Canvas Loop

Michael P. Reilly arcege at shore.net
Fri May 7 14:07:35 EDT 1999


Randall Hopper <aa8vb at vislab.epa.gov> wrote:
:     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)?

It is implimented in a combination of C and very small amounts of Tcl
and Python.  But mostly within the C Tk library.

: The performance of this GUI app is acceptable except for the above loop,
: and it alone can literally take minutes (400-30k iterations).

You can either use one call to create_line or use create_polygon.

  # just get the first endpoint of each line
  vertices = map(lambda a, b: a, lines)
  # add the first vertex to the end to close the polygon
  canvas.create_line( vertices + vertices[:1], width=0 )
or
  canvas.create_polygon( vertices, width=0 )

It will probably take much less time then a Python loop.

  -Arcege





More information about the Python-list mailing list