[Tkinter-discuss] Problem with grid layout

pellegrini pellegrini at ill.fr
Mon Jan 5 12:09:02 CET 2009


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 ?

thank you very much

Eric Pellegrini





More information about the Tkinter-discuss mailing list