Search code examples
tkintertk-toolkitttk

Tk Frame loses its size when creating a child Label


Here's the relevant piece of code

self.testFrame = ttk.LabelFrame(self, height = 300, width = 300)
self.anotherString = ttk.Label(self.testFrame, text="lol")
self.testFrame.grid(column = 0, row = 2)
self.testFrame.pack_propagate(0)
self.anotherString.grid(column = 0, row =0)

A lot of the answers on here told me to use pack_propagate(0), but that doesn't seem to help. The result is a small LabelFrame with the word lol in it, but it should be bigger. Why is it losing its 300x300 size?


Solution

  • You use grid() so you need grid_propagate(0)

    import tkinter as tk
    from tkinter import ttk
    
    root = tk.Tk()
    
    testFrame = ttk.LabelFrame(root, height=300, width=300)
    testFrame.grid(column=0, row=2)
    
    anotherString = ttk.Label(testFrame, text="lol")
    anotherString.grid(column=0, row=0)
    
    #testFrame.pack_propagate(0)
    testFrame.grid_propagate(0)
    
    root.mainloop()