The Canvas Widget

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, -borderwidth, -cursor, -height, -highlightbackground, -highlightcolor, -highlightthickness, -insertbackground, -insertborderwidth, -insertofftime, -insertontime, -insertwidth, -relief, -selectbackground, -selectborderwidth, -selectforeground, -takefocus, -width, -xscrollcommand, and -yscrollcommand.

Other options are:

Canvas Creation Methods

To place graphic elements in a canvas, there are several item creation commands:

Item Tags and IDs

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.

Canvas Methods

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