question: parameters for create_polygon() method

Peter Otten __peter__ at web.de
Thu May 6 02:28:42 EDT 2004


SeeBelow at SeeBelow.Nut wrote:

> The suggestion about a flatten() function is also a good one, but it
> turns out not to be needed.

Looking into the source it turns out that Tkinter has its own flattening
function (implemented in C, with a Python fallback), which ignores None and
processes both tuples and lists:

>>> Tkinter._flatten([((0, 0), (100, 0)), None, ((100, 100), (0, 100)), 50,
70, (50, 30)])
(0, 0, 100, 0, 100, 100, 0, 100, 50, 70, 50, 30)
>>>

So you are not limited to tuples when constructing your polygons:

import Tkinter as tk
root = tk.Tk()
canvas = tk.Canvas(root)
canvas.pack()

line1 = (0, 0), (100, 0)
line2 = (100, 100), (0, 100)
points = [line1, None, line2, 50, 70, (50, 30)]
canvas.create_polygon(fill="red", *points)
root.mainloop()

Peter




More information about the Python-list mailing list