Canvas Options

The options listed in this section affect the entire Canvas widget and the items within it (such as circles, lines, rectangles, text, or other widgets). The following options act as you would expect (as explained in " Button, Checkbutton, and Radiobutton Widgets" for most options and in "The Scrollbar Widget" for the Scrollbar options): -background, -borderwidth, -cursor, -height,-highlightbackground, -highlightcolor, -highlightthickness, -relief, -takefocus, -width, -xscrollcommand, and -yscrollcommand.

There are also several options that are unique to the Canvas widget. When selecting items in the Canvas with the mouse cursor, the Canvas widget does calculations to determine if the mouse cursor is inside or outside the item. The -closeenough option controls how close the mouse must be to the item before it is considered inside the item. The default value for -closeenough is "1.0", which is 1.0 pixels away. Any floating-point number is a valid value (and will always be in pixels) for -closeenough.

We discussed the -scrollregion option briefly in "The Scrollable Region" earlier in this chapter. It takes an array reference, which must contain four coordinates. The coordinates indicate a bounding region for the scrollable area in the Canvas. The coordinates are in this order: [ minx miny maxx maxy ]. You can also think of the coordinates as if they were defining the [ left, top, right, bottom ] edges of the scrollable region.

Normally the Canvas widget limits the user to seeing only the area defined by the -scrollregion option. You can allow the user to scroll beyond this area by using -confine => 0. The default for -confine is 1.

Common Canvas Dash, Stipple, and Tile Options

Jan Nijtman's "dash and image" patches have been incorporated into Perl/Tk. In "Images and Animations" we investigate the basic features of stipples and Jan's tiles. Here we introduce his Canvas "dash and tile" options. They are applicable to most Canvas items, although only -state and -updatecommand apply to embedded widgets.

The following describes a dashSpec and specifies how a dashed line is drawn.

Additional Scrolling Options

The -xscrollcommand and -yscrollcommand options both work as described in "The Scrollbar Widget", but there are two additional options that affect how the Canvas scrolls its contents: -xscrollincrement and -yscrollincrement. Each option takes a valid screen distance for a value. This distance is the unit the Canvas will use to scroll in the associated direction. For instance, if you specify -xscrollincrement => , each time you click an arrow on the horizontal Scrollbar, the contents of the Canvas will shift so the left edge of the contents is an even multiple of 10. Essentially, the Canvas will shift the contents 10 pixels in the arrow's direction.

If the value associated with -xscrollincrement or -yscrollincrement is 0 or less, scrolling is done in normal increments.

Canvas Widget Option List

These options all are used with the Canvas method: