Python论坛  - 讨论区

标题:[python-chinese] Tkinter 中 Frame 实例是 root 组件吗?

2006年03月20日 星期一 10:45

=?ISO-2022-JP?B?GyRCcjJDaRsoQg==?= weizhong2004 at gmail.com
Mon Mar 20 10:45:37 HKT 2006

下面这个例子来自 python 编程金典
在类 LabelDemo中,self显然是 LabelDemo类的实例,而该类是Frame类的子类
也就是self 是一个容器,它用来存放后面的三个label
那么我就看不明白下面高亮的一句了.
self 不就已经是顶层配件了吗?self.master 是谁?
书中说,每个子组件都有名为master的一个属性,它引用该子组件的父组件,在高亮的一行访问的是LabelDemo的父组件(顶级组件),并调用title方法将gui的标题更改成
Labels

莫非Frame 及其子对象并非top配件?最顶层的配件是 window? 迷惑中

# Fig. 10.4: fig10_04.py
# Label demonstration.

from Tkinter import *

class LabelDemo( Frame ):
   """Demonstrate Labels"""

   def __init__( self ):
      """Create three Labels and pack them"""

      Frame.__init__( self )   # initializes Frame instance

      # frame fills all available space
      self.pack( expand = YES, fill = BOTH )
      self.master.title( "Labels" )

      self.Label1 = Label( self, text = "Label with text" )

      # resize frame to accommodate Label
      self.Label1.pack()

      self.Label2 = Label( self,
         text = "Labels with text and a bitmap" )

      # insert Label against left side of frame
      self.Label2.pack( side = LEFT )

      # using default bitmap image as label
      self.Label3 = Label( self, bitmap = "info" )
      self.Label3.pack( side = LEFT )

def main():
   LabelDemo().mainloop()  # starts event loop

if __name__ == "__main__":
   main()


--
开飞机的舒克
http://www.lvye.org/shuke
msn:weizhong at netease.com
my-tag:IM我也在用.但一般只对熟悉的人开.这东西太占时间.相比还是maillist好.让自已思考,让别人思考,让更多人参与.--limodou
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060320/b6310e25/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号