Tkinter pack()方法
这个几何管理器在将小部件放置在父小部件之前,将它们组织成块。
语法
widget.pack( pack_options )
以下是可能选项的列表 –
- expand - 当设置为true时,小部件会扩展以填充小部件所在父容器中未使用的任何空间。
-
fill - 确定小部件是否填充包装程序分配给它的任何额外空间,还是保持自己的最小尺寸:NONE(默认值),X(仅水平填充),Y(仅垂直填充)或BOTH(水平和垂直填充)。
-
side - 决定父容器的哪一侧与其包装在一起:TOP(默认值),BOTTOM,LEFT或RIGHT。
示例
尝试以下示例,将光标移动到不同的按钮上 –
from tkinter import * root = Tk() frame = Frame(root) frame.pack() bottomframe = Frame(root) bottomframe.pack( side = BOTTOM ) redbutton = Button(frame, text="Red", fg="red") redbutton.pack( side = LEFT) greenbutton = Button(frame, text="Brown", fg="brown") greenbutton.pack( side = LEFT ) bluebutton = Button(frame, text="Blue", fg="blue") bluebutton.pack( side = LEFT ) blackbutton = Button(bottomframe, text="Black", fg="black") blackbutton.pack( side = BOTTOM) root.mainloop()
当以上代码被执行时,会产生如下结果−
版权声明:本页面内容旨在传播知识,为用户自行发布,若有侵权等问题请及时与本网联系,我们将第一时间处理。E-mail:284563525@qq.com