Search code examples
pythontkinterframe

Tkinter Frame changes its width and height


For instance, I have 2 frames and both are set to 300x300. On one of them, I put a widget in, and in the other one I don't. The one that I put a widget on just squeezed its size to the widget's size while the first frame kept its frame since its empty.

Can I get around this and have a fixed width and height for the frame no matter what I put?

An example:

from tkinter import *

root = Tk()
root.geometry("1000x1000")
frame1 = Frame(root, bg = "blue", width = 300, height = 300)
frame1.pack()

frame2 = Frame(root, bg = "red", width = 300, height = 300)
label = Label(frame2, text = "hey").pack()
frame2.pack()

Solution

  • Check out this answer: tkinter's .pack_propagate() method

    What you're looking for is pack_propagate