加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

python tkinter pack简析

(2013-11-11 18:07:36)
分类: python-tkinter
pack是tkinter中的一个布局管理模块,与java中的一个布局是一样的道理,其通用公式为:

 

              WidgetObject.pack(option, …)

常用的选择(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()

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有