How to prevent Tkinter labelframe size changes when an empty label is inserted

12,720

If you use a sticky value that sticks the widget to all four sides of its cell rather than just one side, it won't shrink when you put a small label widget in it.

Another option is to call errorArea.grid_propagate(False), which tells the grid area not to shrink or expand to fit its contents. This will often result in undesirable resize behavior, or at least require you to do a little extra work to get the right resize behavior.

Share:
12,720
alwbtc
Author by

alwbtc

Updated on June 05, 2022

Comments

  • alwbtc
    alwbtc almost 2 years

    I create a LabelFrame widget. It has a nice size in the beginning:

    import Tkinter
    form = Tkinter.Tk()
    
    errorArea = Tkinter.LabelFrame(form, text=" Errors ", width=250, height=80)
    errorArea.grid(row=2, column=0, columnspan=2, sticky="E", \
                 padx=5, pady=0, ipadx=0, ipady=0)
    

    enter image description here

    But when I insert an empty string in it, the errorArea widget's size adjusts according to the inserted string:

    errorMessage = Tkinter.Label(errorArea, text="")
    errorMessage.grid(row=0, column=0, padx=5, pady=2, sticky='W')
    

    enter image description here

    How do I give the errorArea widget a fixed size, so that its size won't change according to Lable inserted in it?

  • alwbtc
    alwbtc almost 11 years
    it didn't work, when I use "WENS" in errorArea, it messes the structure of form.
  • Russell Smith
    Russell Smith almost 11 years
    If you could show us more of your code we could probably fix the layout issue.