Creating Items in a Canvas
The whole point of having a Canvas is to put items in it. You can
create arcs, bitmaps, images, lines, rectangles, ovals (circles),
polygons, text, and widgets. Each has an associated
create
XXX method, where the
type of item you want to create replaces the
XXX. Each of the create
methods returns a unique ID, which can be used to
refer to the item later. When you see a method that takes a tag or an
ID as an argument, the ID is the one returned from the
create method.
The Arc Item
When you create an arc, you specify a bounding rectangle with two
sets of x and y coordinates. The arc is drawn within the confines of
the bounding box. The basic createArc statement is
as follows:
$id = $canvas->createArc(x1,y1,x2,y2);
Any additional options used with createArc are
specified after the coordinates:
$id = $canvas->createArc(x1, y1, x2, y2, option => value);
Each option for the arc item can be
used later with the itemcget and
itemconfigure Canvas methods. The options are:
-
-extent =>degrees The length of the arc is specified in degrees by using the
-extentoption. The default-extent(or length) is 90 degrees. The arc is drawn from the starting point (see-startoption) counterclockwise within the rectangle defined by (x1,y1) and (x2,y2). Thedegreesvalue should be between -360 and 360. If it is more or less, the value used is the specified number of degrees modulo 360.Here are some examples of the
-extentoption:# This draws half of an oval $canvas->createArc(0,0,100,150, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access