fill and expand on Tcl/Tk pack command
Archive - Originally posted on "The Horse's Mouth" - 2007-12-13 15:44:31 - Graham Ellispack .this .that -expand true -fill both
Why are there two different options expand and fill? Are they both needed?
expand causes a widget to expand to fill the space available as a window is stretched, and fill causes a widget to be filled to the cell so that it lines up with other widgets.
In order to show you the difference graphically, I wrote this demonstration program:
button .this -text "this" -command exit
button .that -text "Something unthis" -command exit
if {$argv == 1} {
pack .this .that
puts stderr "Neither fill nor expand"
# small buttons in one side of window
} elseif {$argv == 2} {
pack .this .that -fill both
puts stderr "No expand but with fill"
# button widths match
} elseif {$argv == 3} {
pack .this .that -expand true
puts stderr "No fill but with expand"
# buttons distributed through window
} elseif {$argv == 4} {
pack .this .that -expand true -fill both
puts stderr "Both fill and expand"
# buttons expanded to truely fill window
} else {
puts stderr "Usage: $argv0 \[1|2|3|4\]"
exit
}
Neither, and just "expand" ...


"fill", and both ...

