我很喜歡tcl,但新手使用tk。 我想在窗口上顯示一些文本,經過幾次搜索後,我在這裏找到了一個對我來說很好的示例。 我的問題是,顯示不是實時投入,但只有當程序結束。 這是我的程序的主線。終端文本不顯示在tcltk窗口實時
Main_program.tcl
#!/bin/sh
# -*- tcl -*-
# The next line is executed by /bin/sh, but not tcl \
exec /usr/local/Cellar/tcl-tk/bin/tclsh "$0" "[email protected]"
set DEBUG 1
source ./GUI_mgt.tcl
source ./utils.tcl
for {set i 0} {$i<500} {incr i} {
after 10
debug_puts $i
}
utils.tcl
proc debug_puts {message} {
if {$::DEBUG} { writeToLog $message }
}
GUI_mgt.tcl
package require Tk
grid [text .log -state disabled -width 80 -height 24 -wrap none]
proc writeToLog {msg} {
set numlines [lindex [split [.log index "end - 1 line"] "."] 0]
.log configure -state normal
if {$numlines==24} {.log delete 1.0 2.0}
if {[.log index "end-1c"]!="1.0"} {.log insert end "\n"}
.log insert end "$msg"
.log configure -state disabled
}
問:什麼是錯的或在此代碼錯過了什麼? 你知道一些可以用來在單獨窗口上顯示句子的軟件包或例子嗎?
注:我用在MacOS塞拉利昂10.12.5
感謝Brad,你的vwait主意完美工作。 我會嘗試你的第二個想法與單獨的線程。這是一個我喜歡很多的想法。 –