tkinter的pack改变组件在窗口位置
作者:互联网
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)
则结果为:
标签:tkinter,TOP,lab3,lab2,window,组件,side,pack 来源: https://blog.csdn.net/LIZHEMGHONG/article/details/118463442