[Tkinter-discuss] pack geometry manager question

Michael O'Donnell michael.odonnell at uam.es
Wed Sep 19 13:35:42 CEST 2012


Hi Lion,

  At least under my Windows version running Python 3.3.0rc2, and
TK 8.5, I get the initial window is tight to the Entries (no extra space).

However, when I drag the window larger than this minimum, yes,
the second row of entries is spaced down from the top one.

Three changes to your code:

1) I dropped the last frame, which being empty and without specified
dimensions, does nothing.

2) I set the background color of your frames so I can see
which frame is actually consuming what space.

3) I changed the expand=1 for the frames to expand=False,
and now all frames stick to the top, which is what I think you want.

See code below:

from tkinter import *

t = Toplevel(bg="blue")

lbl = Label(t, text="XXXXXXXXXXX")
lbl.pack(side=TOP, anchor=N)

f1 = Frame(t, bg="green")
f1.pack(side=TOP, expand=False, fill=X, anchor=N)

e11 = Entry(f1)
e11.pack(side=LEFT, expand=True, fill=X, anchor=N)
e12 = Entry(f1)
e12.pack(side=LEFT, expand=True, fill=X, anchor=N)

f2 = Frame(t, bg="red")
f2.pack(side=TOP, expand=False, fill=X, anchor=N)

e21 = Entry(f2)
e21.pack(side=LEFT, expand=True, fill=X, anchor=N)
e22 = Entry(f2)
e22.pack(side=LEFT, expand=True, fill=X, anchor=N)



Now, as to why expand=False, fill=X gives the behaviour
you want, I cannot help you. I just much around with these
until I find the soultion. Sorry.

Mick


More information about the Tkinter-discuss mailing list