tcl - terminal text not displayed in tcltk window real time -


i comfortable tcl newbie tk. want display texts on window , after several search found here example seem me. issue display not put in real time when program end. here main lines of program.

main_program.tcl

#!/bin/sh # -*- tcl -*- # next line executed /bin/sh, not tcl \ exec /usr/local/cellar/tcl-tk/bin/tclsh "$0" "$@"  set debug 1  source ./gui_mgt.tcl source ./utils.tcl  {set 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 } 

question: wrong or missed in code ? know package or example can use display sentences on separate window ?

note: use tcl tk 8.6.6 on macos sierra 10.12.5

your test program not written in event driven fashion, problems updating screen exacerbated.

the after 10 statement hang program , not allow event loop reentered. purposes of testing only, try:

set ::w10 0 after 10 [list set ::w10 1] vwait ::w10 

instead of after 10 command. use of vwait command not recommended, nested vwait's not work expected.

when have busy loop, tk program may never have chance re-enter event loop, , display never updated.

the simplest solution put

update  

statement @ end of writetolog procedure. not best way handle type of issue, works.

it slow down loop, window must redrawn each time log message written.

another method put calculation process separate thread or process , send status updates main gui process.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -