[Tutor] Playing with CENTER, Grid, Labels and Entry

Alan Gauld alan.gauld at btinternet.com
Thu Mar 19 01:18:28 CET 2009

"Wayne Watson" <sierra_mtnview at sbcglobal.net> wrote

> I'm using Grid. It's gone pretty well, but I'd like to make it 
> "prettier".

For that Frame is usually your friend. Create your widgets inside
frames and then pack or grid the Frames. You can then use a
combination of padding, filling and anchoring etc in both way
you insert the widgets into the Frame and the way you insert
the Frame into the window.

Personally I find drawing it out with pencil and paper helps a
lot when layouts start to get complicated.

> For example, a row with latitude and longitude gets spread
> across the dialog, whereas, they should be closer together.

If you put them both in a Frame and then put the frame into
one of yourgrid cells they will both be together on one side.

> However, at the moment, I'm trying to build a title across
> row 8. I want some centering of the text, but the methods

Use a Frame to hold the label then use pack to put the label
centred in the Frame. Then grid the frame into your window
spanning cells as needed. Frames are your friend for layout.

To be honest I usually use the packer for the layout of my top
window then use grid inside a Frame. I can then create smaller
frames to insert into the grid.

Don't forget that when creating subframes the subframe
should be used as the parent of the widgets:

fCoords  = Frame(self.master)   # the subframe as child of the main 
eLat = Entry(fCoords,.....)    # use subframe as parent
eLat.grid(row=0, col=0)       # grid it within the subframe so reset 
counts to 0
eLong = Entry(fCoords,.....)  # and here
eLong.grid(row = 0, col=1)
fCoords.grid(row = current, col = whatever)


Alan G
Author of the Learn to Program web site

More information about the Tutor mailing list