I'm trying to pack
(or place
) a widget which is child of the root toplevel .
inside another toplevel, that is a child of .
itself. That is,
% toplevel .tl
.tl
% frame .f
.f
% pack .f -in .tl
can't pack .f inside .tl
However, I've found this code almost works:
% frame .tl
.tl
% frame .f
.f
% pack .f -in .tl
% wm manage .tl
I said almost, because .f
is not visible. It's a bit strange, because if I put a button inside .f
, such as
button .f.b -text FooBar
pack .f.b
I see the empty space reserved by the geometry manager, but no widget is visible.
I'm sure I'm doing something wrong, but I don't know what and why, and the pack
, grid
and place
man pages don't help.
Edit: some details about what I'm doing
I'm trying to build a snit widget which automates some toplevel creation stuff. One thing I usually do is putting a ttk::frame
inside every toplevel I create, and managing it using a pack ... -fill both -expand true
command.
My snidget should always do it, but I'd like to hide it from the user perspective, so that any change to the implementation wouldn't break existing code.
The simple way is this
snit::widget Toplevel {
hulltype toplevel
component f
constructor {args} {
set f [ttk::frame $self.f -padding 2]
pack $f -fill both -expand 1
$self configurelist $args
}
}
but the user must know about the f
component, and create other widgets as children of it.
So, I tried another solution: I use a ttk::frame
widget as hull type, then build a sibling toplevel of the hull, and try to put the hull inside the toplevel.
The code I tried is similar to the following:
snit::widget Toplevel {
hulltype ttk::frame
component tl
constructor {args} {
set segments [split $self .]
set wname [join [lreplace $segments end end _[lindex $segments end]] .]
set tl [frame $wname -width 100 -height 100]
pack $self -in $tl -fill both -expand 1
wm manage $tl
$self configurelist $args
}
}
If it would work as expected, the user could write something like this:
% Toplevel .t
.t
% button .t.b -text Foobar
.t.b
% pack .t.b
and would get a button inside the toplevel .t
build using the snidget.