Tk Code Fragments

The following are some semi useful Tk code fragments

Dynamically Updating Text widget from pipe output

Updates a text widget with text from another process as the text is emitted through the pipe ( rather than waiting till the process finishes).

From Ken Corey (kcorey@eng.sun.com)

#!/usr/local/bin/wish

text .t -yscrollc {.sb set}
scrollbar .sb -command {.t yview}
button .b -text "Quit" -command {destroy .}

pack .sb -side right -fill y
pack .b -side bottom
pack .t -side left -fill both -expand 1


# Open the process we want to monitor hooked up to a pipe 
# swap the #'s to enable 'foo | stdoutin.tcl':
set f [open "|stdoutin.pl" r]
#set f "stdin"

fileevent $f readable {
   .t insert end "[gets $f]\n"
   .t yview end
   update idletasks
}

Making puts redirect output to a Window

From: John Haxby (jch@hazel.pwd.hp.com)
rename puts __puts
proc puts {args} {
    if [llength $args]==1 {
        putsToWindow $args
    } else {
         eval __puts $args
    }
}
# needs handling of nonewline and 
# definition of putsToWindow - creates Text widget if not already and
# adds putted text to end of it ...


Hops (hops@sco.com) $ Last Modified: $Date: 1996/06/14 07:59:47 $: