Canvas rectangle objects

Each rectangle is specified as two points: (x0, y0) is the top left corner, and (x1, y1) is the location of the pixel just outside of the bottom right corner.

For example, the rectangle specified by top left corner (100,100) and bottom right corner (102,102) is a square two pixels by two pixels, including pixel (101,101) but not including (102,102).

Rectangles are drawn in two parts:

• The outline lies inside the rectangle on its top and left sides, but outside the rectangle on its bottom and right side. The default appearance is a one-pixel-wide black border.

For example, consider a rectangle with top left corner (10,10) and bottom right corner (11,11). If you request no border (width=0) and green fill (fill='green'), you will get one green pixel at (10,10). However, if you request the same options with a black border (width=1), you will get four black pixels at (10,10), (10,11), (11,10), and (11,11).

• The fill is the area inside the outline. Its default appearance is transparent. To create a rectangle object on canvas C:

id = C.create_rectangle ( x0, y0, x1, y1, option, ... )

This constructor returns the object ID of the rectangle on that canvas. Options include:

activedash activefill activeoutline activeoutlinestipple activestipple activewidth

These options specify the appearance of the rectangle when its state is ACTIVE, that is, when the mouse is on top of the rectangle. For option values, refer to dash, fill, outline, outlinestipple, stipple, and width below.

dash

To produce a dashed border around the rectangle, use this option to specify a dash pattern. See Section 5.13, "Dash patterns" (p. 16).

dashoffset

Use this option to start the border's dash pattern at a different point in the cycle; see Section 5.13, "Dash patterns" (p. 16).

disableddash disabledfill disabledoutline disabledoutlinestipple disabledstipple disabledwidth

These options specify the appearance of the rectangle when its state is DISABLED.

fill

By default, the interior of a rectangle is empty, and you can get this behavior with fill="". You can also set the option to a color; see Section 5.3, "Colors" (p. 9).

offset

Use this option to change the offset of the interior stipple pattern. See Section 5.14, "Matching stipple patterns" (p. 16).

outline

The color of the border. Default is outline="black".

outlineoffset

Use this option to adjust the offset of the stipple pattern in the outline; see Section 5.14, "Matching stipple patterns" (p. 16).

outlinestipple

Use this option to produce a stippled outline. The pattern is specified by a bitmap; see Section 5.7, "Bitmaps" (p. 12).

state

By default, rectangles are created in the NORMAL state. The state is ACTIVE when the mouse is over the rectangle. Set this option to DISABLED to gray out the rectangle and make it unresponsive to mouse events.

stipple

A bitmap indicating how the interior of the rectangle will be stippled. Default is stipple="", which means a solid color. A typical value would be stipple="gray25". Has no effect unless the fill has been set to some color. See Section 5.7, "Bitmaps" (p. 12).

tags

The tags to be associated with the object, as a sequence of strings. See Section 7.4, "Canvas tags" (p. 21).

width

Width of the border. Default is 1 pixel. Use width=0 to make the border invisible. See Section 5.1, "Dimensions" (p. 9).

0 0

Post a comment