You can place any Tkinter widget onto a canvas by using a canvas window object. A window is a rectangular area that can hold one Tkinter widget. The widget must be the child of the same top-level window as the canvas, or the child of some widget located in the same top-level window.
If you want to put complex multi-widget objects on a
canvas, you can use this method to place a
Frame
widget on the canvas, and
then place other widgets inside that frame.
To create a new canvas window object on a canvas
:C
id
=C
.create_window (x
,y
,option
, ... )
This returns the object ID for the window object. Options include:
anchor | The default is
anchor=CENTER , meaning
that the window is centered on the
( ,
)
position. See Section 4.5, “Anchors” for the
possible values. For example, if you specify
anchor=E , the window will
be positioned so that point
( ,
)
is on the midpoint of its right-hand (east)
edge. |
height | The height of the area reserved for the window. If omitted, the window will be sized to fit the height of the contained widget. See Section 4.1, “Dimensions” for possible values. |
tags | The tags to be associated with the object, as a sequence of strings. See Section 6.1.4, “Canvas tags”. |
width | The width of the area reserved for the window. If omitted, the window will be sized to fit the width of the contained widget. |
window | Use
window=
where
is the widget you want to place onto the canvas.
If this is omitted initially, you can later call
to place the widget
onto the canvas, where
is the window's object ID.. |