Python tkinter -- Chapter 18 Window of Canvas Control

18.2.22 create_window(position, ** options)
can place other tkinter controls in the canvas control. The way to place it is to use widgets. A widget can hold only one control. If you want to place multiple controls, you can use these controls as sub-controls of the Frame control, and put the Frame control into the window component to realize the placement of multiple sub-controls.
The control must be a child control of the canvas control, otherwise it cannot be displayed.

Create a window component at the position (x, y) specified by
position (1) position: coordinates (x, y)
(2) options: the specific meaning of the option

options meaning
anchor Specify the relative position of the window component in the position parameter, which can be N, NE, E, SE, S, SW, W, NW, or CENTER to locate (EWSN stands for east, west, north, south, up north, down south, left west, right east). The default value is CENTER
height Specifies the height of the widget
state Specifies the state of the widget. Can be NORMAL, DISABLED (not available, does not respond to events) and HIDDEN (hidden). The default value is NORMAL
tags Add a label to the created widget
width Specifies the width of the widget
window Specify a widget
18.2.22.1 anchor
Specifies how to place the widget at coordinate point (x,y). There are N, NE, E, SE, S, SW, W, NW, or CENTER. See 18.2.21.3 for details.
import tkinter as tk
root=tk.Tk()
root.geometry('320x240')
b1=tk.Canvas(root)
b2=tk.Entry(b1)
win=b1.create_window(160,40,window=b2,anchor=tk.CENTER)
b1.pack()
root.mainloop()

Result:
insert image description here
18.2.22.2 height
specifies the height of the widget.
18.2.22.3 state
There are three states of the window component: NORMAL, DISABLED and HIDDEN.
18.2.22.4 tags
defines the tags of the widget. It can also be set by other methods.
18.2.22.5 width
defines the width of the widget.
18.2.22.6 window
Specifies the controls to be added to the window. The control must be a child control of the canvas control. See instructions in 18.2.22.1.

Guess you like

Origin blog.csdn.net/weixin_42272768/article/details/100876366