question: parameters for create_polygon() method
Andrew Bennetts
andrew-pythonlist at puzzling.org
Wed May 5 03:47:42 EDT 2004
On Wed, May 05, 2004 at 08:50:24AM +0200, Peter Otten wrote:
> Andrew Bennetts wrote:
>
> > Sorry, I misinterpreted the problem slightly; I just checked the docs for
> > create_polygon and realised it takes an argument that is a sequence of
> > co-ords, rather than a variable number of args that are the co-ords.
>
> I just tried it - it may not be in the docs, but it does work.
> For example
>
[...]
> points = [(20, 20), (50, 150), (200, 50)]
>
> canvas.create_polygon(fill="blue", *points)
[...]
Heh. I guess either the docs I found with google were wrong, or I misread
them :)
Odd, though -- I thought that calls that put non-keyword args after keyword
args were a syntax error, but using varargs syntax seems to workaround that
-- e.g. try:
canvas.create_polygon(fill="blue", (20, 20), (50, 150), (200, 50))
Or without Tk:
>>> def f(*args, **kw): print args, kw
...
>>> f(x=1, 2)
SyntaxError: non-keyword arg after keyword arg
>>> f(x=1, *[2])
(2,) {'x': 1}
Interesting.
-Andrew.
More information about the Python-list
mailing list