Tcl / Tk:滚动条时水平滚动条无法缩小

时间:2015-03-02 03:36:01

标签: scrollbar tcl tk

在以下示例代码中:

proc push_button {} {
    set name [.ent get]
    .txt insert end "Hello, $name."
}
frame .frm -relief groove
label .lab -text "Enter name:"
entry .ent
button .but -text "Push Me" -command "push_button"
frame .textarea
text .txt -width 20 -height 10 \
    -yscrollcommand ".srl_y set" -xscrollcommand ".srl_x set"
scrollbar .srl_y -command ".txt yview" -orient v
scrollbar .srl_x -command ".txt xview" -orient h
pack .lab -in .frm
pack .ent -in .frm
pack .frm
pack .but
grid .txt   -in .textarea -row 1 -column 1
grid .srl_y -in .textarea -row 1 -column 2 -sticky ns
grid .srl_x -in .textarea -row 2 -column 1 -sticky ew
pack .textarea

按下按钮Push Me,新文本字符串将添加到文本框中。在.txt insert end "Hello, $name."中,没有新的行\n符号。所以它应该形成一个很长的字符串。

我的理解是随着字符串变长,水平scollbar应该相应地改变和缩小。但xscollbar无法按预期工作。

我的工具需要这样的效果。那么对此有何帮助?

1 个答案:

答案 0 :(得分:1)

您遇到的行为是因为文本换行。默认的文本换行模式似乎是char(当达到宽度限制时,文本将被拆分为更多行,并且它将基于字符分割。)

更改以下行以获得您期望看到的行为:

text .txt -width 20 -height 10 \
    -yscrollcommand ".srl_y set" -xscrollcommand ".srl_x set" -wrap none

我在最后添加了-wrap none

相关问题