Canvas Methods

In addition to configure and cget, the following methods are supported by the Canvas widget:

addtag

Defines a tag for an already created canvas item. For example, to assign a tag called "everything" to all items in a canvas:

$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:

above

Assigns the tag to the item above the specified item in the display list

all

Assigns the tag to all items in the canvas

below

Assigns the tag to the item below the specified item in the display list

closest

Assigns the tag to the item closest to the specified x,y coordinate

enclosed

Assigns the tag to all items that are completely enclosed within the specified bounding box

overlapping

Assigns the tag to all items that are even partially inside the specified bounding box

withtag

Assigns the tag to all items with the specified tag

bind

Binds a callback to an item. (To bind a callback to the Canvas widget itself, you must specify Tk::bind.)

bbox

Returns the bounding box of an item. For example, to get the bounding box for all items in the canvas:

$canvas->bbox("all");
itemconfigure

Configures one of the items within the canvas. Works just like the configure method for widgets, but the first argument is the tag name or ID for the canvas item.

itemcget

Gets configuration information for one of the items within the canvas. Works just like the cget method for widgets, but the first argument ...

Get Perl in a Nutshell, 2nd Edition 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.