Tkinter: why does an empty frame not shrink?

Fredrik Lundh Fredrik.Lundh at p98.f112.n480.z2.fidonet.org
Thu Jul 1 05:21:42 EDT 1999


From: "Fredrik Lundh" <fredrik at pythonware.com>

Greg McFarlane wrote:
> 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()

</F>




More information about the Python-list mailing list