[Tkinter-discuss] Problem with grid layout

Guilherme Polo ggpolo at gmail.com
Mon Jan 5 13:07:11 CET 2009


On Mon, Jan 5, 2009 at 9:09 AM, pellegrini <pellegrini at ill.fr> wrote:
> Hello everybody,
>
> I have a problem with the grid management.
>
> Here is the following simple script:
>
> ######################################################################
> from Tkinter import *
> root = Tk()
> f = Frame(root)
> f.grid(row = 0, column = 0, sticky = W)
>
> f1 = Frame(f, relief = GROOVE, bd = 2)
> f1.grid(row = 0, column = 0, sticky = W)
> str1 = StringVar(root,'%-20s' % 'Label')
> Label(f1, textvariable = str1, anchor = W).grid(row = 0, column = 0, sticky
> = W)
> Button(f1, text = 'Button1').grid(row = 0, column = 1)
>
> f2 = Frame(f, relief = GROOVE, bd = 2)
> f2.grid(row = 1, column = 0, sticky = W)
> str2 = StringVar(root,'%-20s' % 'BiggerLabel')
> Label(f2, textvariable = str2, anchor = W).grid(row = 0, column = 0, sticky
> = W)
> Button(f2, text = 'Button2').grid(row = 0, column = 1)
>
> root.mainloop()
> ######################################################################
>
> I would expect that script to produce two frames with exactly the same size
> but it is not the case.
> However the two labels have the same size by construction (i.e. 20).
>
> Would you have any idea ?
>

strings of same length won't give you labels of same size, since that
matters nothing when you are not using a monospace font.
If you just want frames with same size, change theirs stickys to "ew".

> thank you very much
>
> Eric Pellegrini
>
>

-- 
-- Guilherme H. Polo Goncalves


More information about the Tkinter-discuss mailing list