Create a canvas for drawing with the Canvas method. The Canvas widget uses a coordinate system with the x coordinate increasing as you move right, and the y coordinate increasing as you move down (i.e., the y coordinate is mathematically upside-down). The x and y coordinates are specified in pixels by default.
$parentwidget->Canvas (options)
The standard configuration options that apply to Canvas are: -background, -bor-derwidth, -cursor, -height, -highlightbackground, -highlightcolor, -highlight-thickness, -insertbackground, -insertborderwidth, -insertofftime, -inserton-time, -insertwidth, -relief, -selectbackground, -selectborderwidth, -selectfore-ground, -state, -takefocus, -width, -xscrollcommand, and -yscrollcommand.
Other options are:
To place graphic elements in a canvas, there are several item creation methods:
$canvas->createArc(0,0,40,100, -extent => 360);
The -extent option gives a number between 0 and 360 defining the length of the arc. The default -extent is 90, or 1/4 of an oval; an extent of 360 gives you a full oval. The complete list of options to createArc is:
$canvas -> createBitmap(0, 0, -bitmap => 'calculator');
Options are:
$canvas->createImage(0,0, -image => $imgptr);
Options are:
$imgptr = $mainwindow->Photo(-file => "doggie.gif");
$canvas->createLine (0,0,100,100,100,0);
The first four coordinates are required. Any additional coordinates are taken to represent a continuation of that line. Options are:
$canvas->createOval(50,50,150,150);
Options are:
$canvas -> createPolygon(0,0,130, 20, 90, -35);
Options are:
$canvas->createRectangle(0,0,100,100);
Options are:
$canvas->createText(130,-40, -text => "Broadway");
Options are:
There is a set of methods for manipulating text items within a Canvas widget. For each of these methods, the first argument is the tag name or tag ID, and subsequent arguments use text indexes as described for the Text widget.
Each item in a Canvas widget is given a unique ID when it is created. This ID is returned from the canvas creation command. In addition, each item can have a tag associated with it, either when created or with the addtag method. You can use either the ID or the tag to refer to an item in the canvas. Unlike IDs, tags do not have to be unique, which makes it possible to configure several items as a group.
Two special tags are created automatically. The "all" tag refers to all items in the canvas. The "current" tag refers to the item that the cursor is currently over, if any.
In addition to configure and cget, the following methods are supported by the Canvas widget:
$canvas->addtag("everything", "all");
To assign the tag origin to the item closest to the coordinates (0,0):
$canvas->addtag("origin", "closest", 0, 0);
The full list of identifiers is:
$canvas->bbox("all");
$canvas->move("circle1", 100, 100);
$canvas->scale("all", 0, 0, .5, .5);
Copyright © 2002 O'Reilly & Associates. All rights reserved.