pack layout

Probably perceive

The simplest kind of layout: (specify the side parameter)

tk.Label(window, text='顶部label',bg='green').pack(side='top')    # 上
tk.Label(window, text='底部label',bg='green').pack(side='bottom') # 下
tk.Label(window, text='左边label',bg='green').pack(side='left')   # 左
tk.Label(window, text='右边label',bg='green').pack(side='right')  # 右

Effect:
Insert picture description here
If it is used directly: (Do not specify the side parameter)
For example:

'''
创建两个label,pack()不加参数效果
'''
l1 = tk.Label(window, text='hello world', bg='gray', font=('Arial', 12), width=30, height=2)
l1.pack()
l2=tk.Label(window, text='hello world', bg='gray', font=('Arial', 12), width=30, height=2)
l2.pack()

The effect is shown in the figure (the default parameter is side='top'):
Insert picture description here

Pack() parameter summary

side: Where is the button docked in the window

  • left: 左

  • top: up

  • right: right

  • botton: down

fill: fill

  • x: horizontal filling

  • y: vertical filling

  • both: horizontal and vertical filling

  • none: no fill

expand:

  • yes: extend the entire blank area

  • no: do not expand

anchor: alignment

  • N: Go north

  • E: East right

  • S: Go south

  • W: West Left

  • CENTER: middle

padx: the outer margin in the x direction

pady: the outer margin in the y direction

ipadx: padding in the x direction

ipady: padding in the y direction

Guess you like

Origin blog.csdn.net/qq_41985293/article/details/106317527