Entry
Tkinter: Shrinking an empty frame
Jul 5th, 2000 10:02
Nathan Wallace, unknown unknown, Hans Nowak, Snippet 257, Fredrik Lundh
"""
Packages: gui.tkinter
"""
"""
> If you have several child widgets packed in a frame and you unpack the
> children one by one, the frame will gradually get smaller, except when
> the last child is unpacked, in which case the frame does not resize.
> Does anyone know why the frame does not shrink to 0x0 when you unpack
> the last child?
when geometry propagation is on (as it is by default), the
packer sets the size of the geometry master to exactly fit
the child widgets. if there are no children, the packer
simply keeps the current size.
> Any solution?
why not just insert an extra widget that you never delete?
"""
from Tkinter import *
root = Tk()
root.geometry("400x400")
frame = Frame(background="red")
frame.pack(fill=X)
Frame(frame).pack()
for i in range(5):
button = Button(frame, text="Unpack me")
button.configure(command=button.pack_forget)
button.pack()
mainloop()