Can you change a Tkinter widget's master?

Isaac To Kar Keung kkto at csis.hku.hk
Mon May 14 14:35:59 EDT 2001


>>>>> "Fredrik" ==   <sternber at socrates.Berkeley.EDU> writes:

    Fredrik> The problem is that the Label, Entry and ButtonBox won't have
    Fredrik> dialog as their master.  Their master will be '.'.  And so it
    Fredrik> won't be possible to arrange them inside dialog, which was my
    Fredrik> goal.

Remember that the real parent really have very little implication for widget
packing.  For example:

  from Tkinter import *

  def f():
    return Label(text='Hello, world!')	# Always create at root level

  a=Tk()	# Okay, a is .
  b=Frame(border=5,relief='raised')
  b.pack()
  d=Frame(border=4,relief='sunken',width=50,height=50)
  d.pack()
  c=f()		# c is .somethingelse
  c.pack(in_=b)	# pack c in b
  a.update()
  a.after(5000)	# wait for some time
  c.pack(in_=d) # move c to d
  a.mainloop()

There is no requirement that the parent widget is the geometric master.  Any
descendent of the parent can do the job.  Since f() above create in the root
level, every widget can be its master.  Of course, there is not a lot of fun
if you put a widget in_ its descendent. ;p

Regards,
Isaac.



More information about the Python-list mailing list