Given a frame which manages its children with the grid
geometry manager, changes to the size of children are reported reported or not to the frame as events depending on whether the frame size is constrained in the axes of the change. See following table:
frame restricted in direction |
child resized in direction |
event reported to frame |
none |
width |
✓ yes |
width |
width |
x no |
height |
width |
✓ yes |
width |
height |
✓ yes |
height |
height |
x no |
width & height |
width |
✓ yes |
width & height |
height |
✓ yes |
This seems inconsistent to me: if we report geometry changes when both width&height are constrained, we should report them as well when either width or height alone are constrained.
To give some context, this impacted me in the context of using a widget similar to https://wiki.tcl-lang.org/page/A+scrolled+frame, where the internal $w.scrolled frame manages its widgets with grid and their size grow. When either the width or height are constrained (happens often when using -fill
x
, y
or none
).
Find below a reproducer, both interactive and batch:
package require Tk;
set nconfs 0;
set cont .t.f;
set item .t.f.c;
destroy .t;
toplevel .t;
wm geometry .t 400x400;
frame $cont -relief solid -borderwidth 2 -width 0 -height 0;
frame $item -background red -height 100 -width 100;
place $cont -rely 0.25 -relx 0.25;
grid $item -row 0 -column 0 -sticky news;
# Count number of configure events on the container as a result of the item
# being resized.
bind $cont <Configure> {incr ::nconfs};
if {true} {
proc toggleconfigure {w opt val1 {val2 ""}} {
$w configure $opt [expr {[$w cget $opt] eq $val1 ? $val2 : $val1}];
}
proc toggleplace {w opt val1 {val2 ""}} {
place configure $w $opt [expr {[dict get [place info $w] $opt] eq $val1 ? $val2 : $val1}];
}
button .t.bcw -text "resize item -width" -command {toggleconfigure $item -width 100 500}
button .t.bch -text "resize item -height" -command {toggleconfigure $item -height 100 500}
button .t.bpw -text "restrict container -width" -command {toggleplace $cont -relwidth 0.5 ""}
button .t.bph -text "restrict container -height" -command {toggleplace $cont -relheight 0.5 ""}
button .t.nconfs -textvariable ::nconfs -command {set ::nconfs 0};
place .t.bcw -rely 0.0 -relx 0.0 -relwidth 0.5 -relheight 0.05;
place .t.bch -rely 0.0 -relx 0.5 -relwidth 0.5 -relheight 0.05;
place .t.bpw -rely 0.05 -relx 0.0 -relwidth 0.5 -relheight 0.05;
place .t.bph -rely 0.05 -relx 0.5 -relwidth 0.5 -relheight 0.05;
place .t.nconfs -rely 0.1 -relx 0.5 -relwidth 0.5 -relheight 0.05;
}
proc test {relwidth relheight} {
global nconfs;
global cont;
global item;
$item configure -width 100 -height 100;
place $cont -relwidth $relwidth -relheight $relheight;
update; update idletasks; update;
set nconfs 0;
$item configure -width 200;
update; update idletasks; update;
$item configure -height 200;
update; update idletasks; update;
return $nconfs;
}
puts "relwidth={} relheight={}: #<Configure> [test {} {}]";
puts "relwidth=0.5 relheight={}: #<Configure> [test 0.5 {}]";
puts "relwidth={} relheight=0.5: #<Configure> [test {} 0.5]";
puts "relwidth=0.5 relheight=0.5: #<Configure> [test 0.5 0.5]";
puts "---"