tcl - Can't pack a widget inside a sibling toplevel -
i'm trying pack
(or place
) widget child of root toplevel .
inside toplevel, child of .
itself. is,
% toplevel .tl .tl % frame .f .f % pack .f -in .tl can't pack .f inside .tl
however, i've found code almost works:
% frame .tl .tl % frame .f .f % pack .f -in .tl % wm manage .tl
i said almost, because .f
not visible. it's bit strange, because if put button inside .f
, such as
button .f.b -text foobar pack .f.b
i see empty space reserved geometry manager, no widget visible.
i'm sure i'm doing wrong, don't know , why, , pack
, grid
, place
man pages don't help.
edit: details i'm doing
i'm trying build snit widget automates toplevel creation stuff. 1 thing putting ttk::frame
inside every toplevel create, , managing using pack ... -fill both -expand true
command.
my snidget should it, i'd hide user perspective, change implementation wouldn't break existing code.
the simple way 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 user must know f
component, , create other widgets children of it.
so, tried solution: use ttk::frame
widget hull type, build sibling toplevel of hull, , try put hull inside toplevel.
the code tried similar 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 work expected, user write this:
% toplevel .t .t % button .t.b -text foobar .t.b % pack .t.b
and button inside toplevel .t
build using snidget.
widgets except toplevels arranged in strict hierarchy of containment; widget .foo
contains widget .foo.bar
, in turn contains .foo.bar.grill
, etc. toplevel widgets children of root window.
there 2 things can change this.
you can use
wm manage
(requires 8.5 or later) turn standard frame widget toplevel, ,wm forget
reverse (you'll have re-pack
/re-grid
too). (i don't think supported on osx/aqua.)frame .foo # define contents... wm manage .foo
# later... wm forget .foo pack .foo
this useful pair of operations making torn-off windows toolbars. there's demo in tk widget demo.
you can turn frame (or toplevel) container widget @ creation time (set
-container
option true in creation options; can't done later). can id of window widget (withwinfo id
) , tell toplevel at creation time use widget id parent via-use
option.frame .foo -container 1 set id [winfo id .foo] toplevel .bar -use $id
note in case, on unix/x11 ids can passed other processes , used, , need not refer windows created tk. (some applications can reverse, embedding inside window given id defined tk.) on windows , osx/aqua, ids guaranteed work within single process.
what don't know whether operation want perform can done either of these 2 possible operations; you're not quite clear higher-level perspective of you're trying do. don't mix particularly well, -container
, -use
creation-time-only options, , subsequently read-only, , can't change name hierarchy (that's totally fixed after creation). sophisticated stuff may require step , formally define model have multiple widget layouts being views of.
Comments
Post a Comment