Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

widget layout

Status
Not open for further replies.

tlo

Programmer
Oct 27, 2003
5
US
I like to arrange the widgets as shown below:

button1 button2 button3

button4 button5 button6

I use the following:

pack .b1 .b2 .b3 -side left

That takes care the first row. Then for the next row:

pack .b4 .b5 .b6 -side left

They all line up in a row which is not what I want. I just cannot come up with an option that allows button4 through button6 to be on the next row.




 
You got the hard way.
For array arrangement the placer to use is grid:
Code:
grid .b1 -row 0 -column 0
grid .b2 -row 0 -column 1
grid .b3 -row 0 -column 2
grid .b4 -row 1 -column 0
grid .b5 -row 1 -column 1
grid .b6 -row 1 -column 2

Voila!
(I never tried to use 'pack' for such an arrangement so I can't help you to find how to deal with)

ulis
 
The grid geometry manager is definitely the way to go with a layout like that. By the way, with regular grids like that you can also take advantage of grid's ability to grid an entire row at a time:

Code:
grid .b1 .b2 .b3 -padx 4 -pady 2
grid .b4 .b5 .b6 -padx 4 -pady 2

With each grid command, you can list all of the widgets to appear on a given row in the order that you want them to appear. Each subsequent grid command of this type creates a new row in the grid. Any gridding options (the -padx and -pady settings in this case) are applied to all widgets in that row. You can actually come up with some pretty sophisticated layouts with this shortcut. Try this:

Code:
option add *font {Helvetica 24 bold}
label .a -text "A" -background red
label .b -text "B" -background blue
label .c -text "C" -background green
label .d -text "D" -background yellow
label .e -text "E" -background orange

grid  .a   -  .b  -sticky nsew
grid  .c  .d   ^  -sticky nsew
grid   ^  .e   -  -sticky nsew

Of course, gridding by specific row and column like ulis did gives you control over the individual gridding options of each specific widget.

By the way, you can achieve the 2-row layout originally asked for using only pack, but it requires frames.

By the way, remember that you can't combine pack and grid within a single container. Bad things happen if you try. (Usually, the window doesn't appear, but your CPU time gets chewed up by the two geometry managers fighting with each other.) Within a given toplevel or frame, you must choose either pack or grid to lay out all of its immediate children. But that doesn't stop you from using pack to arrange the widgets in a toplevel, and then using grid to lay out the widgets in a frame inside of that window. - Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top