pack的side默认值为TOP
from tkinter import *
window = Tk()
window.title('排列方法')
lab1 = Label(window, text='one', bg='lightyellow', width=20)
lab2 = Label(window, text='two', bg='lightgreen', width=20)
lab3 = Label(window, text='three', bg='lightblue', width=20)
lab1.pack(side=TOP) # pack的side默认值为TOP
lab2.pack(side=TOP)
lab3.pack(side=TOP)
window.mainloop()
运行结果:
side改为BOTTOM,LEFT,RIGHT,其结果分别为:
此外,也可以是混合排列的,例如,若将上面对应代码改为:
lab1.pack(side=TOP)
lab2.pack(side=LEFT)
lab3.pack(side=RIGHT)
则结果为:
若改为:
lab1.pack(side=RIGHT)
lab2.pack(side=TOP)
lab3.pack(side=TOP)
则结果为: