[Tutor] Please Critque Tkinter Class for Newbie

Michael P. Reilly arcege@speakeasy.net
Fri, 13 Jul 2001 08:28:23 -0400 (EDT)


Sheila King wrote
> OK, but if one has a class derived from the Tkinter Frame Widget that
> has several other types of widgets on it (such as a button and a label
> and so forth), and those items are placed on the Frame subclass with the
> pack manager, then won't this incompatibility still exist? (i.e. someone
> will not then be able to place the Frame subclass on another widget
> unless they use the place geometry manager???). Or maybe not. OK, I will
> experiment with this. (I haven't tried using grid(), yet...)

Each widget inside a single container needs to use the same geometry
manager.  But outside of that, they can be different.

>>> from Tkinter import *
>>> root1 = Tk()
>>> frame11 = Frame(root1, relief=GROOVE, bd=2)
>>> frame12 = Frame(root1, relief=GROOVE, bd=2)
>>> Button(frame11, text='0,0').grid(row=0, column=0)
>>> Button(frame11, text='0,1').grid(row=0, column=1)
>>> Button(frame11, text='1,0').grid(row=1, column=0)
>>> Button(frame11, text='1,1').grid(row=1, column=1)
>>> Label(frame12, text='top'   ).pack(side=TOP)
>>> Label(frame12, text='bottom').pack(side=BOTTOM)
>>> Label(frame12, text='left'  ).pack(side=LEFT)
>>> Label(frame12, text='right' ).pack(side=RIGHT)
>>> frame11.place(relx=0, rely=0, relwidth=0.5, relheight=0.5, anchor=NW)
>>> frame12.place(relx=1, rely=1, relwidth=0.5, relheight=0.5, anchor=SE)
>>> root1.mainloop()

Each frame (including the root widget) is using a different geometry
manager, but all the widgets in an enclosing widget (root1, frame11,
or frame12) must use the same manager.  I.e., both frames are place'd in
root1, but all the buttons are grid'd in frame11 and all the labels are
pack'd into frame12.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |