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

6.11. The canvas window object

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:

anchorThe default is anchor=CENTER, meaning that the window is centered on the (x, y) 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 (x, y) is on the midpoint of its right-hand (east) edge.
heightThe 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.
tagsThe tags to be associated with the object, as a sequence of strings. See Section 6.1.4, “Canvas tags”.
widthThe width of the area reserved for the window. If omitted, the window will be sized to fit the width of the contained widget.
windowUse window=w where w is the widget you want to place onto the canvas. If this is omitted initially, you can later call C.itemconfigure ( id, window=w) to place the widget w onto the canvas, where id is the window's object ID..