Tkinter and fixed-size frames

msoulier msoulier at gmail.com
Wed Mar 29 08:51:25 EST 2006


Hello,

A friend is having an issue with Tkinter that I'm not able to help him
with, so I'm posting here.

He'd like to put something inside of a frame without the frame
automagickally resizing.

Example:

from Tkinter import *

root = Tk()

# with these 2 frames by themselves, they are the
# size requested (the second one is "elastic")

f01 = Frame( root, width="40px", height="60px",
             background="#FFE0E0",
             borderwidth=1,
             relief=GROOVE,
             )
f01.pack( side=LEFT )

f02 = Frame( root, width="40px", height="60px",
             background="#E0FFE0",
             borderwidth=1,
             relief=GROOVE,
             )
f02.pack( side=LEFT, fill=Y )

# uncomment this, and the left frame changes its size to this
#l01 = Label( f01, text="01",
#             background="#E0E0FF",
#             borderwidth=2,
#             relief="ridge",
#             )
#l01.pack( side=TOP, expand=Y, fill=BOTH )

# and this doesn't help either
#s01 = Frame( f01 )
#s01.pack( side=TOP, expand=Y, fill=BOTH )

root.mainloop()

Any suggestions on how to maintain the size of the frame when you pack
a label into it like this?

Thanks,
Mike




More information about the Python-list mailing list