2012-01-25 7 views
1

私はtextTkウィジェットのサイズを制限することに関して質問があります。私は2つのtextウィジェットがお互いの上に並んでいる次のコードを持っています。問題は、「Box2」を含むテキストウィジェットのサイズを変更すると、下の画像に示すように消えてしまうことです。Tcl/Tk:リサイズの `text`ウィジェットを制限する

"Box2"も表示されるようにサイズを変更したいと思います。 "Box2"を表示できない場合は、サイズ変更の特定の段階で小さいサイズへのサイズ変更を許可しないでください(より大きなサイズへのサイズ変更は許可する必要があります)。問題を再現するHere "Box2" text widget disappears

コードをリサイズ

ノーマルサイズThis the normal sized one

は次のとおりです。

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" 
+2

packの代わりに.t1/.t2を使用し、rows/columnsにweight /および/またはminsizeオプションを設定してみてください。グリッドの詳細については、http://www.tkdocs.com/tutorial/grid.htmlを参照してください。 – schlenk

+0

@schlenkチップをありがとう。できます。私は答えとして作業コードを掲示します。 – Anand

答えて

1

シュレンク作品によって示唆されているように。

set st1 [scrolled_text .t1 -width 80 -height 40] 
set st2 [horiz_scrolled_text .t2 -width 80 -height 2] 

grid .t1 -sticky news 
grid .t2 -sticky news 

# row 0 - t1; row 1 - t2 
grid rowconfigure . 0 -weight 10 -minsize 5 
grid rowconfigure . 1 -weight 2 -minsize 1 
grid columnconfigure . 0 -weight 1 

$st1 insert end "Box1" 
$st2 insert end "Box2" 

ここでのキーはrowconfigureであり、重量はそれに割り当てられています。私は、heightの値に従って、10.t1に、2.t2に割り当てました。 minsize51に設定して、特定の最小値を超えてウィンドウを縮小しないようにしました。

weightはに設定されています。水平方向のサイズを変更しようとすると、ウィンドウが拡大され、空白が残るためです。

関連する問題