Tcl 无法在笔记本中向下滚动
我创建了一个tcl笔记本,它有两个选项卡,如果文件太大,我无法向下滚动。在这里共享我的代码。 要执行此代码,您需要2个文件(Warning.txt和Error.txt),在运行此代码之前将它们放在同一目录中。 请创建两个文件Error.txt和Warning.txt。 给它放一些内容,让它有10000行Tcl 无法在笔记本中向下滚动,tcl,tk,Tcl,Tk,我创建了一个tcl笔记本,它有两个选项卡,如果文件太大,我无法向下滚动。在这里共享我的代码。 要执行此代码,您需要2个文件(Warning.txt和Error.txt),在运行此代码之前将它们放在同一目录中。 请创建两个文件Error.txt和Warning.txt。 给它放一些内容,让它有10000行 #!/usr/bin/wish -f # package require Tk proc noteb {} { global rundir logfile frame .lpo
#!/usr/bin/wish -f
#
package require Tk
proc noteb {} {
global rundir logfile
frame .lpo
pack .lpo -side top -fill both -expand true
#cd $rundir
set ft [exec grep -c Warning ./Warning.txt]
puts $ft
set ert [exec grep -c Error ./Error.txt]
puts $ert
pack [frame .fa] -fill both -side top
pack [ttk::notebook .fa.nb] -fill both
set gt "Errors"
set bt "Warnings"
set delim ":"
set rt [concat [string trim $bt][string trim $delim][string trim $ft]]
set dt [concat [string trim $gt][string trim $delim][string trim $ert]]
if {$ft > 0} {
.fa.nb add [frame .fa.nb.f1] -text $rt
} else {
.fa.nb add [frame .fa.nb.f1] -text "Warnings"
}
pack [frame .fa.nb.f1.f11] -side top -fill both -expand true
pack [text .fa.nb.f1.f11.t1 -bg LightYellow -borderwidth 2 -width 80 -height 6 -relief raised -setgrid true ] -side left -fill both -expand true
scrollbar .fa.nb.f1.f11.scroll -command {.fa.nb.f1.f11.t1 yview}
pack .fa.nb.f1.f11.scroll -side right -fill y
set fp1 [open Warning.txt r]
set v [read $fp1]
.fa.nb.f1.f11.t1 insert 1.0 $v
close $fp1
if {$ert > 0} {
.fa.nb add [frame .fa.nb.f2] -text $dt
} else {
.fa.nb add [frame .fa.nb.f2] -text "Errors"
}
pack [frame .fa.nb.f2.f11] -side top -fill both -expand true
pack [text .fa.nb.f2.f11.t1 -bg LightYellow -borderwidth 2 -width 80 -height 6 -relief raised -setgrid true ] -side left -fill both -expand true
scrollbar .fa.nb.f2.f11.scroll -command {.fa.nb.f2.f11.t1 yview}
pack .fa.nb.f2.f11.scroll -side right -fill y
set fp [open Error.txt r]
set c [read $fp]
.fa.nb.f2.f11.t1 insert 1.0 $c
close $fp
}
button .mn -text summary -command {noteb}
pack .mn -side left
我认为如果您在文本小部件上设置-yscroll选项,它会起作用。我认为如果您在文本小部件上设置-yscroll选项,它会起作用。在下面的几行中,您告诉滚动条有关文本小部件的信息,但没有告诉文本小部件有关滚动条的信息。你需要两者兼而有之
pack [text .fa.nb.f1.f11.t1 -bg LightYellow -borderwidth 2 -width 80 -height 6 -relief raised -setgrid true ] -side left -fill both -expand true
scrollbar .fa.nb.f1.f11.scroll -command {.fa.nb.f1.f11.t1 yview}
pack .fa.nb.f1.f11.scroll -side right -fill y
让它变成这样:
text .fa.nb.f1.f11.t1 -bg LightYellow -borderwidth 2 -width 80 -height 6 \
-relief raised -setgrid true -yscroll {.fa.nb.f1.f11.scroll set}
scrollbar .fa.nb.f1.f11.scroll -command {.fa.nb.f1.f11.t1 yview}
pack .fa.nb.f1.f11.t1 -side left -fill both -expand true
pack .fa.nb.f1.f11.scroll -side right -fill y
尽管我实际上倾向于这样做:
set w .fa.nb.f1.f11
text $w.t1 -bg LightYellow -borderwidth 2 -width 80 -height 6 -relief raised \
-setgrid true -yscroll [list $w.scroll set]
scrollbar $w.scroll -command [list $w.t1 yview]
pack $w.t1 -side left -fill both -expand true
pack $w.scroll -side right -fill y
将容器小部件名称放在变量中有助于使代码更加合理,并使文本和滚动条之间的关联更加明显。(如果需要,还可以更容易地重构代码。)在下面的这些行中,您可以告诉滚动条有关文本小部件的信息,但不能告诉文本小部件有关滚动条的信息。你需要两者兼而有之
pack [text .fa.nb.f1.f11.t1 -bg LightYellow -borderwidth 2 -width 80 -height 6 -relief raised -setgrid true ] -side left -fill both -expand true
scrollbar .fa.nb.f1.f11.scroll -command {.fa.nb.f1.f11.t1 yview}
pack .fa.nb.f1.f11.scroll -side right -fill y
让它变成这样:
text .fa.nb.f1.f11.t1 -bg LightYellow -borderwidth 2 -width 80 -height 6 \
-relief raised -setgrid true -yscroll {.fa.nb.f1.f11.scroll set}
scrollbar .fa.nb.f1.f11.scroll -command {.fa.nb.f1.f11.t1 yview}
pack .fa.nb.f1.f11.t1 -side left -fill both -expand true
pack .fa.nb.f1.f11.scroll -side right -fill y
尽管我实际上倾向于这样做:
set w .fa.nb.f1.f11
text $w.t1 -bg LightYellow -borderwidth 2 -width 80 -height 6 -relief raised \
-setgrid true -yscroll [list $w.scroll set]
scrollbar $w.scroll -command [list $w.t1 yview]
pack $w.t1 -side left -fill both -expand true
pack $w.scroll -side right -fill y
将容器小部件名称放在变量中有助于使代码更加合理,并使文本和滚动条之间的关联更加明显。(如果需要的话,还可以更容易地重构代码。)