Most of the topics I came across deals with how to not shrink the Frame
with contents, but I'm interested in shrinking it back after the destruction of said contents. Here's an example:
import tkinter as tk
root = tk.Tk()
lbl1 = tk.Label(root, text='Hello!')
lbl1.pack()
frm = tk.Frame(root, bg='black')
frm.pack()
lbl3 = tk.Label(root, text='Bye!')
lbl3.pack()
lbl2 = tk.Label(frm, text='My name is Foo')
lbl2.pack()
So far I should see this in my window:
Hello!
My name is Foo
Bye!
That's great, but I want to keep the middle layer interchangeable and hidden based on needs. So if I destroy the lbl2
inside:
lbl2.destroy()
I want to see:
Hello!
Bye!
But what I see instead:
Hello!
███████
Bye!
I want to shrink frm
back to basically non-existence because I want to keep the order of my main widgets intact. Ideally, I want to run frm.pack(fill=tk.BOTH, expand=True)
so that my widgets inside can scale accordingly. However if this interferes with the shrinking, I can live without fill/expand
.
I've tried the following:
pack_propagate(0)
: This actually doesn't expand the frame at all pastpack()
.- Re-run
frm.pack()
: but this ruins the order of my main widgets. .geometry('')
: This only works on theroot
window - doesn't exist forFrame
s.frm.config(height=0)
: Oddly, this doesn't seem to change anything at all.frm.pack_forget()
: From this answer, however it doesn't bring it back.
The only option it leaves me is using a grid
manager, which works I suppose, but not exactly what I'm looking for... so I'm interested to know if there's another way to achieve this.