Next / Previous / Contents / TCC Help System / NM Tech homepage

6. The Canvas widget

A canvas is a rectangular area intended for drawing pictures or other complex layouts. On it you can place graphics, text, widgets, or frames. See the following sections for methods that create objects on canvases:

To create a Canvas object:

    w = Canvas ( master, option=value, ... )

The constructor returns the new canvas widget. Supported options include:

bd or borderwidthBorder width in pixels.
bg or backgroundBackground color of the canvas. Default is a light gray, about "#E4E4E4".
closeenoughA float that specifies how close the mouse must be to an item to be considered inside it. Default is 1.0.
confineIf true (the default), the canvas cannot be scrolled outside of the scrollregion (see below).
cursorCursor used in the canvas. See Section 4.8, “Cursors”.
heightSize of the canvas in the Y dimension. See Section 4.1, “Dimensions”.
highlightbackgroundColor of the focus highlight when the widget does not have focus. See Section 23, “Focus: routing keyboard input”.
highlightcolorColor shown in the focus highlight.
highlightthicknessThickness of the focus highlight.
reliefThe relief style of the canvas. Default is FLAT. See Section 4.6, “Relief styles”.
scrollregionA tuple (w, n, e, s) that defines over how large an area the canvas can be scrolled, where w is the left side, n the top, e the right side, and s the bottom.
selectbackgroundThe background color to use displaying selected items.
selectborderwidthThe width of the border to use around selected items.
selectforegroundThe foreground color to use displaying selected items.
takefocusNormally, focus (see Section 23, “Focus: routing keyboard input”) will cycle through this widget with the tab key only if there are keyboard bindings set for it (see Section 24, “Events” for an overview of keyboard bindings). If you set this option to 1, focus will always visit this widget. Set it to "" to get the default behavior.
widthSize of the canvas in the X dimension. See Section 4.1, “Dimensions”.
xscrollincrementNormally, canvases can be scrolled horizontally to any position. You can get this behavior by setting xscrollincrement to zero. If you set this option to some positive dimension, the canvas can be positioned only on multiples of that distance, and the value will be used for scrolling by scrolling units, such as when the user clicks on the arrows at the ends of a scrollbar. For more information on scrolling units, see Section 16, “The Scrollbar widget”.
xscrollcommandIf the canvas is scrollable, this attribute should be the .set() method of the horizontal scrollbar.
yscrollincrementWorks like xscrollincrement, but governs vertical movement.
yscrollcommandIf the canvas is scrollable, this attribute should be the .set() method of the vertical scrollbar.