Tkinter and fixed-size frames

M

msoulier

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
 
M

msoulier

calling pack_propagate(0) on the parent widget should work:

Indeed it does.

Many thanks.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top