Xdialog --gauge
显然,您应该获得一个值,该值会不时更新为“一秒钟”。此增量通过已预先配置为提供累进计数的for
循环完成。
根据我的测试,我对
tcl / tk
的了解可以达到以下程度:proc bar { pos } {
global txt
set txt $pos
}
set btn [button .btn -text "Play" -relief groove -command { bar $pos }]
scale .scl -length 200 -width 5 -orient horizontal -from 0 -to 100 -resolution 1 -variable value -sliderlength 5 -sliderrelief flat -activebackground blue -command { bar } -showvalue 0
label .lbl -textvariable txt -width 5
grid $btn -row 0 -column 0
grid .scl -row 0 -column 1
grid .lbl -row 0 -column 2
global value
for {set value 0} {$value < 10} {incr value} {
after 1000; # delay
if {$value < 10} { puts "Number: $value" }
bind . "$btn invoke"
}
这有效,所以在控制台中..它不显示窗体,窗口中的小部件缓慢移动。因此,我需要经验最丰富的人的帮助,如何获得此帮助?我创建了多帧动画以获得更好的主意。看:
coroutine countUp apply {{} { # <<< launch coroutine for asynchronous state
global value
for {set value 0} {$value < 10} {incr value} {
after 1000 [info coroutine]; yield; # <<< suspend coro for 1 second
puts "Number: $value"
}
}}
((可以在没有协程的情况下编写此代码,但是代码不太清楚。)并且如果需要进度条,建议使用
ttk::progressbar
。纠正用户视觉提示的含义,等等。
after 1000; # delay
只是阻塞,不允许Tcl / Tk进行任何处理。由于您的程序尚未进入事件循环,因此将不会显示任何内容。在某些情况下,任何最终替换“ after”命令的代码都将具有允许屏幕更新的延迟。
# don't put the bind inside the for loop # is this even needed? bind . "$btn invoke" set ::waitvar 0 for {set value 0} {$value < 10} {incr value} { # a simplistic solution for purposes of this example # vwait cannot be nested, and should be used very carefully or not at all. after 1000 set ::waitvar 1 vwait ::waitvar set ::waitvar 0 }
更好的方法将更像是:
proc updateScale { v } { global value set value $v } proc checkProgress { } { # query the progress of the task and see how far along it is set progress [queryProgress] updateScale $progress after 1000 [list checkProgress] } # schedule a call to checkProgress to start things off. after 1000 [list checkProgress] # and now the program enters the event loop