Hiding widgets it Tkinter and shrinking the frame/window? -- a partial answer

Russell E. Owen owen at astrono.junkwashington.emu
Tue Feb 27 11:45:12 EST 2001


To partially answer my own post...

In article <97efnv$tqq$1 at nntp6.u.washington.edu>, "Russell E. Owen" 
<owen at astrono.junkwashington.emu> wrote:

>I am trying to generate a window with basic options always showing and 
>additional panels that are hidden or displayed if needed. I can easily 
>show/hide widgets, but the window does not shrink after a widget is 
>hidden. Is there some basic trick to this?

The basics of show/hide are to pack() or pack_forget() (if using the 
pack manager). Unfortunately, pack_forget loses track of where the 
unpacked widget goes.

To work around this, what I was doing was:
- create an enclosing frame for each hideable widget and have that be 
the master for the hideable widget
- pack(side=LEFT, anchor=NW) or pack_forget() to show/hide
Unfortunately, the enclosing frame wasn't shrinking when the hideable 
widget was unpacked, hence the window wasn't shrinking either.

Just for the heck of it, I tried a variation that worked:
- create an enclosing frame to enclose a set of hideable widgets
- pack an empty (hence zero-sized) placeholder frame to the left of each 
hideable widget
- use pack(side=LEFT, anchor=NW, after=<placeholder>) to show the 
widget, and pack_forget() to hide it
In this case the enclosing frame and window did shrink when a widget was 
hidden.

I have no idea why the second techinque worked when the first one did 
not, as they are very similar. But heck, whatever works. (If anybody 
does have an explanation I'd love to hear it).

I plan to try the gridder, as well, since it appears one can ungrid 
items without forgetting their information (using grid_remove). It'd be 
nice to dispense with the placeholder frames.

-- Russell



More information about the Python-list mailing list