pack()是python tk部件在窗口布局的方法之一,本文重点探讨fill和expand属性是如何配合工作,进而实现部件在不同方向上的拉伸效果。
本文重点探讨fill和expand属性的使用方法
pack()部分属性如下:
- side: 表示部件放置的位置,top(默认), bottom, left, or right
- fill表示部件在是否在某方向填充 : none(默认), x, y, or both
- expand表示部件在x,y方向上是否拉伸, expand=1/0或tk.YES/tk.NO,
- 当side='top/bottom'时,控制部件在y方向上是否拉伸
- 当side='left/right'时,控制部件在x方向上是否拉伸
root=tk.Tk()
root.title("控件布局pack")
root.geometry("500x300")
lab1=tk.Label(root,text="标签一",width="6",height="1",bg="lightgrey")
lab2=tk.Label(root,text="标签二",width="6",height="1",bg="lightgrey")
lab3=tk.Label(root,text="标签三",width="6",height="1",bg="lightgrey")
lab4=t