I have question on limiting the resizing the text Tk widget. I have the following code with two text widgets lined up on top of each other. The problem is when I resize the text widget containing “Box2” just disappears as shown in images below.
I want to do resizing such that “Box2” is also seen. If at certain stage of resizing if “Box2” can’t be shown then resizing to a smaller size should be disallowed (though resizing to a bigger size should be allowed).
Normal size
Resized 
The code to reproduce the problem is:
#----------------------------------------------
# scrolled_text from Brent Welch's book
#----------------------------------------------
proc scrolled_text { f args } {
frame $f
eval {text $f.text -wrap none \
-xscrollcommand [list $f.xscroll set] \
-yscrollcommand [list $f.yscroll set]} $args
scrollbar $f.xscroll -orient horizontal \
-command [list $f.text xview]
scrollbar $f.yscroll -orient vertical \
-command [list $f.text yview]
grid $f.text $f.yscroll -sticky news
grid $f.xscroll -sticky news
grid rowconfigure $f 0 -weight 1
grid columnconfigure $f 0 -weight 1
return $f.text
}
proc horiz_scrolled_text { f args } {
frame $f
eval {text $f.text -wrap none \
-xscrollcommand [list $f.xscroll set] } $args
scrollbar $f.xscroll -orient horizontal -command [list $f.text xview]
grid $f.text -sticky news
grid $f.xscroll -sticky news
grid rowconfigure $f 0 -weight 1
grid columnconfigure $f 0 -weight 1
return $f.text
}
set st1 [scrolled_text .t1 -width 40 -height 10]
set st2 [horiz_scrolled_text .t2 -width 40 -height 2]
pack .t1 -side top -fill both -expand true
pack .t2 -side top -fill x
$st1 insert end "Box1"
$st2 insert end "Box2"
Using
gridinstead ofpackas suggested by schlenk works.The key here is
rowconfigureand the weight’s assigned to it. I have assigned10to.t1and2to.t2in accordance to theirheightvalues. I have also set theminsizeto5and1so that we do not shrink the window beyond a certain minimum.The
columnconfigurehasweightset to1because if we try to resize horizontally the windows should expand and fill instead of leaving empty spaces.