Max line coords canvas.create_line() can display?

Jørgen Hansen jorgenhansen at hotmail.com
Thu Sep 5 03:25:20 EDT 2002


"Fredrik Lundh" <fredrik at pythonware.com> wrote in message news:<5pid9.5885$e5.1033551 at newsb.telia.net>...
> "revyakin" wrote:
> 
> > Is there a limit of line coords (x1,y1,...xn,yn) which a Tk Canvas
> > create_line method can display? I found that I can display a line
> > consisting of 5000 x,y points, but a line of 20 000 points does not
> > get displayed.
> 
> there shouldn't be a limit.
> 
> can you perhaps post a (short) code snippet that illustrates
> the problem?

Hi 

the small program below fails to draw the line, when it is called with
an integer larger than or equal to 16384. I only tested the script on
a Windows 98 machine with Python 2.1.3.

Regards
Jorgen


--- Code start ---
import random, sys
from Tkinter import *

WIDTH = 300
HEIGHT = 200

def randomcoor(n, xmin, xmax, ymin, ymax): 
    """ Generate n sets of random coordinates within the bounds. """
    x = []
    y = []
    for i in range(n):
         x.append(random.randrange(xmin, xmax, 1))
         y.append(random.randrange(ymin, ymax, 1))
    return zip(x,y)         
             

def draw(coor):
    """ Draw a line for the list of coordinates. """    
    root = Tk()
    canvas = Canvas(root, width=WIDTH, height=HEIGHT)
    canvas.pack()
    canvas.create_line(coor)
    root.mainloop()
    

if __name__ == '__main__':
    """ Call the script with an integer number. """
    coor = randomcoor(int(sys.argv[1]), 0, WIDTH-1, 0, HEIGHT-1) 
    draw(coor)   
--- code end ---



More information about the Python-list mailing list