私はtext
Tk
ウィジェットのサイズを制限することに関して質問があります。私は2つのtext
ウィジェットがお互いの上に並んでいる次のコードを持っています。問題は、「Box2」を含むテキストウィジェットのサイズを変更すると、下の画像に示すように消えてしまうことです。Tcl/Tk:リサイズの `text`ウィジェットを制限する
"Box2"も表示されるようにサイズを変更したいと思います。 "Box2"を表示できない場合は、サイズ変更の特定の段階で小さいサイズへのサイズ変更を許可しないでください(より大きなサイズへのサイズ変更は許可する必要があります)。問題を再現する
コードをリサイズ
ノーマルサイズ
は次のとおりです。
grid
の代わり
pack
を使用して
#----------------------------------------------
# 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"
packの代わりに.t1/.t2を使用し、rows/columnsにweight /および/またはminsizeオプションを設定してみてください。グリッドの詳細については、http://www.tkdocs.com/tutorial/grid.htmlを参照してください。 – schlenk
@schlenkチップをありがとう。できます。私は答えとして作業コードを掲示します。 – Anand