python tkinter pack简析

分类: python-tkinter |
pack是tkinter中的一个布局管理模块,与java中的一个布局是一样的道理,其通用公式为:
常用的选择(option)有:
-
expand:当值为“yes”(或者YES
tkinter模块中 “yes”==YES) 时,side选项无效。组件显示在父配件中心位置;若fill选项为”both”,则填充父组件的剩余空间,其默认值为NO。 - http://s1/mw690/002USHL5ty6E8Np7oAg60&690tkinter
pack简析" TITLE="python tkinter pack简析" />
- fill:填充x(y)方向上的空间,当属性side=”top”或”bottom”时,填充x方向;当属性side=”left”或”right”时,填充”y”方向;当expand选项为”yes”时,填充父组件的剩余空间。
- 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()