[Tutor] placing widgets

Alan Gauld alan.gauld at btinternet.com
Wed Jan 26 01:39:16 CET 2011


"W S" <wynnstinson at rocketmail.com> wrote

> trouble with my combobox placement on the frame.  is there a way to 
> more
> explicitly place it other than:  This method does not give a lot of 
> control
> xx=apply(OptionMenu,(self,TCase)+tuple(TestCase))
> xx.grid(row=1, sticky=E+W)

There are basically 3 layout managers in Tk.

pack() is the simplest and gives the programmer least control
but generally yields a usable GUI even if the user messes around
with fonts and sizing etc.

grid() is next easiest since it represents the window as a
table into whose cells you insert the widgets. This gives more
control but can lead to strange results on resizing.

place() is the one that many beginners think is easiest because
it uses actual coordinates. It allows very precise positioning
provided the user doesn't resize the window or change font sizes

Most Tk programmers use grid() and pack(), often a combination.
I tend to use pack at the top kevel to create a set of Frames.
Then inside the Frames I use either pack or grid as appropriate
for the layout I want. That provides flexibility plus adaptability
to user changes.

All of the managers have a slew of options that can be used
to fine tune the spacing, directional bias, etc. RTFM for details.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list