text
Tk
위젯의 크기를 제한하는 것에 관한 질문이 있습니다. 두 개의 text
위젯을 서로 겹쳐서 다음 코드를 작성했습니다. 문제는 아래 이미지와 같이 "Box2"가 포함 된 텍스트 위젯의 크기를 변경하면됩니다.Tcl/Tk : 리사이즈`텍스트`위젯 제한
"Box2"도 표시되도록 크기를 조정하고 싶습니다. "Box2"를 표시 할 수없는 경우 크기 조정의 특정 단계에서 더 작은 크기로 크기를 조정하면 안됩니다 (더 큰 크기로 조정할 수 있어야하지만).
보통 크기
문제를 재현하기위한 코드 크기 조정 는
입니다 : 슈렝 작동에 의해 제안
#----------------------------------------------
# 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"
.t1/.t2와 함께 pack 대신'grid'를 사용하고 행/열에 weight/및/또는 minsize 옵션을 설정하십시오. 그리드에 대한 자세한 내용은 http://www.tkdocs.com/tutorial/grid.html을 참조하십시오. – schlenk
@schlenk 팁 주셔서 감사. 그것은 작동합니다. 답변으로 작업 코드를 게시합니다. – Anand