2012-01-25 2 views
1

textTk 위젯의 크기를 제한하는 것에 관한 질문이 있습니다. 두 개의 text 위젯을 서로 겹쳐서 다음 코드를 작성했습니다. 문제는 아래 이미지와 같이 "Box2"가 포함 된 텍스트 위젯의 크기를 변경하면됩니다.Tcl/Tk : 리사이즈`텍스트`위젯 제한

"Box2"도 표시되도록 크기를 조정하고 싶습니다. "Box2"를 표시 할 수없는 경우 크기 조정의 특정 단계에서 더 작은 크기로 크기를 조정하면 안됩니다 (더 큰 크기로 조정할 수 있어야하지만).

보통 크기 Here "Box2" text widget disappears

문제를 재현하기위한 코드 크기 조정 This the normal sized one

입니다 : 슈렝 작동에 의해 제안

#---------------------------------------------- 
# 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

.t1/.t2와 함께 pack 대신'grid'를 사용하고 행/열에 weight/및/또는 minsize 옵션을 설정하십시오. 그리드에 대한 자세한 내용은 http://www.tkdocs.com/tutorial/grid.html을 참조하십시오. – schlenk

+0

@schlenk 팁 주셔서 감사. 그것은 작동합니다. 답변으로 작업 코드를 게시합니다. – Anand

답변

1

대신 packgrid 사용.

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 값에 따라 을 .t12에서 .t2으로 지정했습니다. minsize51으로 설정하여 특정 최소값 이상으로 창을 축소하지 않도록했습니다.

weight은 으로 설정되어 있습니다. 가로 크기를 조정하려고하면 빈 공간을 남기지 않고 창을 확장하여 채워야하기 때문입니다.