Next / Previous / Contents

8.15. Canvas window objects

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:

Table 15. Canvas window options

anchor The default is anchor=tk.CENTER, meaning that the window is centered on the (x, y) position. See Section 5.5, “Anchors” for the possible values. For example, if you specify anchor=tk.E, the window will be positioned so that point (x, y) 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 5.1, “Dimensions” for possible values.
state By default, window items are in the tk.NORMAL state. Set this option to tk.DISABLED to make the window unresponsive to mouse input, or to tk.HIDDEN to make it invisible.
tags If a single string, the window is tagged with that string. Use a tuple of strings to tag the window with multiple tags. See Section 8.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=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..