Name
create_line
Synopsis
c
.create_line(*coordinates
, **line_options
)
Creates a line
item with vertices at the given
coordinates
and returns the
item’s handle.
coordinates
must be an even number of
positional parameters, alternately x
and
y
values for each vertex of the line. Canvas
coordinates, by default, are in pixels, with the origin (coordinates
0,0
) in the upper left corner, the
x
coordinate growing rightward, and the
y
coordinate growing downward. You may set
different coordinate systems on c
, but I
do not cover these possibilities in this book.
line_options
may include:
-
arrow
Sets which ends of the line have arrow heads; may be
NONE
(default),FIRST
,LAST
, orBOTH
-
fill
The line’s color (default is black)
-
smooth
If true, the line is drawn as a smooth curve (a B-spline); otherwise (default), the line is drawn as a polygonal (a sequence of line segments)
-
tags
A string (to assign a single tag to this item) or a tuple of strings (to assign multiple tags to this item)
-
width
Width of the line in pixels (default
1
)
For example:
x
=c.create_line(0,150, 50,100, 0,50, 50,0 smooth=1)
draws a somewhat S-like curve on c
, and
binds the curve’s handle to variable
x
. You can then change the
curve’s color to blue with:
c
.itemconfig(x,fill='blue')
Get Python in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.