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 8.7, “Canvas
arc objects”.
.create_bitmap()
: An image
as a bitmap. See
Section 8.8, “Canvas
bitmap objects”.
.create_image()
: A graphic
image. See Section 8.9, “Canvas
image objects”.
.create_line()
: One or more
line segments. See Section 8.10, “Canvas
line objects”.
.create_oval()
: An ellipse;
use this also for drawing circles, which are a special
case of an ellipse. See Section 8.11, “Canvas
oval objects”.
.create_polygon()
: A
polygon. See Section 8.12, “Canvas
polygon objects”.
.create_rectangle()
: A
rectangle. See Section 8.13, “Canvas
rectangle objects”.
.create_text()
: Text
annotation. See Section 8.14, “Canvas
text objects”.
.create_window()
: A
rectangular window. See Section 8.15, “Canvas
window objects”.
To create a Canvas
object:
w
= tk.Canvas(parent
,option
=value
, ...)
The constructor returns the new Canvas
widget. Supported options include:
Table 6. Canvas
widget options
bd or
borderwidth | Width of the border around the outside of the canvas; see Section 5.1, “Dimensions”. The default is two 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 5.8, “Cursors”. |
height | Size of the canvas in the Y dimension. See Section 5.1, “Dimensions”. |
highlightbackground | Color of the focus highlight when the widget does not have focus. See Section 53, “Focus: routing keyboard input”. |
highlightcolor | Color shown in the focus highlight. |
highlightthickness | Thickness of the focus highlight. The default value is 1. |
relief |
The relief style of the canvas. Default is tk.FLAT . See Section 5.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 53, “Focus: routing keyboard input”)
will cycle through this widget with the tab key
only if there are keyboard bindings set for it (see
Section 54, “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 5.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 22, “The Scrollbar widget”.
|
xscrollcommand |
If the canvas is scrollable, set this option to the
.set() method of the horizontal
scrollbar.
|
yscrollincrement |
Works like xscrollincrement , but
governs vertical movement.
|
yscrollcommand |
If the canvas is scrollable, this option should be the
.set() method of the vertical scrollbar.
|