Version 16 of frame

Updated 2016-09-20 20:03:20 by oehhar

http://www.tcl.tk/man/tcl8.5/TkCmd/frame.htm


Jeffrey Hobbs has written, "The whole container/use idea is nice, but was only pushed far enough to enable embedding Tk into Netscape/IE. There are definite problems with handling focus and message passing ..."

So I guess it is up to the Tk community to jump in and improve this capability? Let's use "Combining GUI applications developed with Tk and 'native' Windows toolkits" as a home for such progress.


Frame does not shrink to 0 height if last children is unpacked/ungridded

HaO 2016-09-07: (issue is present with pack and grid and with frame, ttk::frame and ttk::labelframe)

Giving a frame with two children:

pack [frame .f -height 1]
pack [entry .f.e1] [entry .f.e2]

When on children is unpacked, the frame resizes to the size required by the other children:

pack forget .f.e1

When the last children is unpacked, the frame does not resize:

pack forget .f.e2

-> The frame keeps the size of the entry widget.

To avoid this effect, there are two solutions on clt (Thread "frame auto resize to 0 if forgetting packed subwidget", date 2016-09-05):

Solution 1: pack an invisible frame

bll: Just pack a dummy frame in the collapsing frame:

pack [frame .f] [frame .f.d]
pack [entry .f.e1] [entry .f.e2]

Solution 2: set -height of the frame to 1

Alexandru Dadalau I use the -height property in order to shrink the frame back after the "pack forget".

pack forget .f.e2
.f configure -height 1

This works without a dummy widget but shows a frame of height 1.

Explanation by Joe English on CLT

Frame widgets normally don't request a size of their own, to avoid fighting with the geometry manager if they contain slaves (which is the normal case). But if the last slave is removed, the geometry manager no longer controls the size of the master and makes no further size requests.

So with nobody making size requests for the frame, it'll just stay at whatever size it happens to be at the time, until something else triggers geometry propagation, such as the user explicitly configuring a (nonzero) -width or -height, or adding a new slave window.

> What is the purpose of this behaviour ? Bug or feature ?

I suspect it's just how things work; this seems like a corner case that was probably never considered and for which there's no obvious right answer.

  TIP proposal to fix this issue

Here is a TIP proposal sent 2016-09-20 to start fixing this issue.

Title:          Automatically resize frame-style widgets to minimum size if last sub-child is not managed any more
Version:        $Revision: 1.0 $
Author:         Harald Oehlmann <[email protected]>
Type:           Project
Keywords:       Tk
Tcl-Version:    8.6.6

~ Abstract

A '''text'''-like widget has 0x0 (client) size if created.
If children are added by pack/grid and the last children is unpacked/grid, the frame-like widget does not return to the 0x0 (client) size.
Instead, it keeps the size of the last packed item.

This TIP describes a technical way to avoid this property which feels like a bug.

~ Rationale

A '''frame''' keeping a size without reason just feels like a bug and mostly lead to unwanted results.
There are no workarounds without issues ([http://wiki.tcl.tk/frame]) and thus, a clear solution would be great.

~ Proposed Change

Emiliano has proposed the following including a patch in [https://core.tcl.tk/tk/info/2863003fff]:

Define a virtual event '''<<GeometryManager>>''' which informs the master (a frame-like widget) that it has no child widget any more and that its size is not managed any more by grid/pack.

In consequence, the frame-like widget should resize to the initial size.

~ Additional information and examples

   *   frame wiki page: [http://wiki.tcl.tk/frame]
   *   Tk bug ticket: [https://core.tcl.tk/tk/info/d6b95ce49207c823]
   *   Tk patch ticket: [https://core.tcl.tk/tk/info/2863003fff]
   *   Discussion on the core list: [http://code.activestate.com/lists/tcl-core/16363/]

~ Compatibility

Fixing the issue breaks visual compatibility.
Nevertheless, as it is seen as a bug, this is ok.

~ Reference Implementation

A reference implementation is available in tk ticket [2863003fff].

~ Copyright

This document has been placed in the public domain.