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:
.create_arc()
: A slice out
of an ellipse. See
Section 6.3, “The canvas arc object”.
.create_bitmap()
: An image
as a bitmap. See
Section 6.4, “The canvas bitmap object”.
.create_image()
: A graphic
image. See Section 6.5, “The canvas image object”.
.create_line()
: One or more
line segments. See Section 6.6, “The canvas line object”.
.create_oval()
: An ellipse;
use this also for drawing circles, which are a special
case of an ellipse. See Section 6.7, “The canvas oval object”.
.create_polygon()
: A
polygon. See Section 6.8, “The canvas polygon object”.
.create_rectangle()
: A
rectangle. See Section 6.9, “The canvas rectangle object”.
.create_text()
: Text
annotation. See Section 6.10, “The canvas text object”.
.create_window()
: A
rectangular window. See Section 6.11, “The canvas window object”.
To create a Canvas
object:
w
= Canvas (master
,option
=value
, ... )
The constructor returns the new canvas widget. Supported options include:
bd or
borderwidth | Border width in pixels. |
bg or
background | Background color
of the canvas. Default is a light gray, about
"#E4E4E4" . |
closeenough | A float that specifies how close the mouse must be to an item to be considered inside it. Default is 1.0. |
confine | If true (the default), the canvas cannot be
scrolled outside of the
scrollregion (see below). |
cursor | Cursor used in the canvas. See Section 4.8, “Cursors”. |
height | Size of the canvas in the Y dimension. See Section 4.1, “Dimensions”. |
highlightbackground | Color of the focus highlight when the widget does not have focus. See Section 23, “Focus: routing keyboard input”. |
highlightcolor | Color shown in the focus highlight. |
highlightthickness | Thickness of the focus highlight. |
relief | The relief style of the canvas. Default is
FLAT . See Section 4.6, “Relief styles”. |
scrollregion | A tuple
( that
defines over how large an area the canvas can be
scrolled, where
is the left side,
the top,
the right side, and
the bottom. |
selectbackground | The background color to use displaying selected items. |
selectborderwidth | The width of the border to use around selected items. |
selectforeground | The foreground color to use displaying selected items. |
takefocus | Normally, 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. |
width | Size of the canvas in the X dimension. See Section 4.1, “Dimensions”. |
xscrollincrement | Normally, 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”. |
xscrollcommand | If the canvas is scrollable, this attribute
should be the .set() method
of the horizontal scrollbar. |
yscrollincrement | Works like
xscrollincrement , but
governs vertical movement. |
yscrollcommand | If the canvas is scrollable, this attribute
should be the .set() method
of the vertical scrollbar. |