Tkinter and fixed-size frames

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • msoulier

    #1

    Tkinter and fixed-size frames

    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="#FF E0E0",
    borderwidth=1,
    relief=GROOVE,
    )
    f01.pack( side=LEFT )

    f02 = Frame( root, width="40px", height="60px",
    background="#E0 FFE0",
    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="#E0 E0FF",
    # 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

  • Fredrik Lundh

    #2
    Re: Tkinter and fixed-size frames

    "msoulier" <msoulier@gmail .com> wrote:
    [color=blue]
    > Any suggestions on how to maintain the size of the frame when you pack
    > a label into it like this?[/color]

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



    </F>



    Comment

    • msoulier

      #3
      Re: Tkinter and fixed-size frames

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

      Indeed it does.

      Many thanks.

      Mike

      Comment

      Working...