[Tkinter-discuss] moving from pack to grid
klappnase at web.de
Mon Nov 27 18:55:47 CET 2006
On Sun, 26 Nov 2006 19:30:51 -0800
"Tony Cappellini" <cappy2112 at gmail.com> wrote:
> What args do I need to move the label to the bottom of the window, and
> centered so it extends to both left and right edges?
> I don't like to hard-code a row number, I'd rather make it dynamic in case
> the window grows or shrinks.
in order to make the label through all grid columns, use:
label.grid(row=5, column=0, columnspan=<number-of-columns>)
If you want the label to use more space than it actually needs, use the grid() command's
sticky option. You can pass one or more of 'n', 's', 'w' and 'e' to the sticky
argument; sticky='w' will put the widget to the leftmost edge of its parent,
sticky='ew' will stretch it from left to right, so in your case you might want:
label.grid(row=5, column=0, columnspan=<number-of-columns>, sticky='ews')
This stretching beyond the widget's requested width will however only take effect, if you
specify the "weight" for the parent's grid row, resp. column:
(this is similar to pack(fill='y')).
I hope this helps
More information about the Tkinter-discuss