Text Tcl/Tk:限制调整“文本”小部件的大小
我对限制Text Tcl/Tk:限制调整“文本”小部件的大小,text,tcl,widget,tk,Text,Tcl,Widget,Tk,我对限制文本Tk小部件的大小有疑问。我有下面的代码,其中两个文本小部件排列在一起。问题是当我调整包含“Box2”的文本小部件的大小时,它会消失,如下图所示 我想调整大小,以便也能看到“Box2”。如果在调整大小的特定阶段,如果无法显示“Box2”,则不允许调整到较小的大小(尽管应允许调整到较大的大小) 正常尺寸 调整大小 重现问题的代码是: #---------------------------------------------- # scrolled_text from Brent Wel
文本
Tk
小部件的大小有疑问。我有下面的代码,其中两个文本
小部件排列在一起。问题是当我调整包含“Box2”的文本小部件的大小时,它会消失,如下图所示
我想调整大小,以便也能看到“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"
使用
grid
代替schlenk works建议的pack
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
,并为其分配了权重。我已根据高度值将10
分配给.t1
和2
分配给.t2
。我还将minsize
设置为5
和1
,这样我们就不会将窗口缩小到超过某个最小值
columnconfigure
将weight
设置为1
,因为如果我们尝试水平调整大小,窗口应该展开并填充,而不是留下空白 尝试使用grid
而不是使用.t1/.t2打包,然后在行/列上设置weight/and/or minsize选项。有关grid的更多信息,请参阅。@schlenk谢谢您的提示。它起作用了。我将发布工作代码作为答案。