9.5. Canvas Options

The options listed in this section affect the entire canvas widget and the items within it. Items are circles, lines, rectangles, text, or other widgets. These options act as you would expect them to (as explained in Chapter 3, for most options and in Chapter 6 for the scrollbar options): -background, -borderwidth, -cursor, -height, -highlightbackground, -highlightcolor, -highlightthickness, -relief, -takefocus, -width, -xscrollcommand, and -yscrollcommand.

9.5.1. New Options

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.

I discussed the -scrollregion option briefly in "The Scrollable Region" earlier in this chapter. It takes a list reference, and that list 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 ...

Get Learning Perl/Tk 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.