1#!/bin/sh 2#\ 3exec itkwish $0 4# ---------------------------------------------------------------------- 5# EXAMPLE: show "TextInfo" and "MessageInfo" widgets in action 6# ---------------------------------------------------------------------- 7# COURSE: Object-Oriented Programming with [incr Tcl] 8# AUTHOR: Michael J. McLennan, Bell Labs Innovations 9# ====================================================================== 10# Copyright (c) 1996 Lucent Technologies 11# ====================================================================== 12lappend auto_path . 13 14if {[string match *color [winfo screenvisual .]]} { 15 option add *textBackground ivory startupFile 16 option add *MessageInfo.background DarkSeaGreen startupFile 17 option add *TextInfo.background DarkSeaGreen startupFile 18 option add *activeBackground ForestGreen startupFile 19 option add *activeForeground white startupFile 20 option add *selectForeground white startupFile 21 option add *selectBackground ForestGreen startupFile 22} 23 24label .label -text "View File:" 25pack .label -anchor w 26 27entry .file 28pack .file -fill x 29 30bind .file <KeyPress-Return> {show_file [.file get]} 31 32proc show_file {file} { 33 set cmd { 34 set fid [open $file r] 35 set info [read $fid] 36 close $fid 37 } 38 if {[catch $cmd] == 0} { 39 set win [TextInfo .#auto -wrap none] 40 $win display $info 41 } else { 42 MessageInfo .#auto -message "Cannot read file:\n$file" 43 } 44} 45