Updated 2003-04-23 19:38:40

Richard Suchenwirth 2003-03-28 - Here is a little animation example: a message that is slowly, character after character, displayed on a text widget, giving the impression that it was being typed in real time. The word wrap is interesting to watch (that would not happen on a typewriter ;-)
 proc slowtext {w text} {
     if {$text != ""} {
	 $w insert end [string index $text 0]
	 $w see end
	 after 100 [list slowtext $w [string range $text 1 end]]
     }
 }
 # little demo
 pack [text .t -font {Courier 16 bold} -width 20 -height 4 -wrap word]
 slowtext .t "Tcl is one of the best scripting languages.
 Tk is one of the best toolkits for building graphical user interfaces.
 Both of them allow you to achieve much with little effort."

FW: Or this one, which simulates human typing by having a random-distribution-within-a-fixed-range duration between each character.
 proc slowtext {w text} {
     if {$text != ""} {
	 $w insert end [string index $text 0]
	 $w see end
	 after [expr {50 + int(rand()*50)}] [list slowtext $w [string range $text 1 end]]
     }
 }

escargo 31 Mar 2003 - This page had been well structured for being reaped by wiki-reaper and wish-reaper; with the second definition of slowtext I don't know if that's still the case. It would be helpful for code authors to consider that adding code might make pages unreapable.

FW: What would be a "reap-safe" way of providing an alternate definition?

escargo 23 Apr 2003 - Just imagine all the code was in one file concatenated together. You could either surround some of the code with the if 0 { structure so that it was ignored, or you could give the revised proc a different name. You could even take the revision with suitable test data onto a different page and refer to it here.

Category Example | Category Animation | Arts and crafts of Tcl-Tk programming