#!/bin/sh ##\ exec wish "$0" "$@" package require BWidget package require Tk proc openfile {} { global hw set filename [tk_getOpenFile] # Cancel returns an empty string if {[string bytelength $filename] != 0} { set fp [open $filename r] $hw.sw.t delete 1.0 end $hw.sw.t insert end [read $fp] close $fp } } proc savefile {} { global hw set filename [tk_getSaveFile] # Cancel returns an empty string if {[string bytelength $filename] != 0} { set fp [open $filename w] puts $fp [$hw.sw.t get 1.0 end] close $fp } } # Create main frame MainFrame .mf pack .mf -fill both -expand yes # Create toolbar set tb [.mf addtoolbar] set bbox [ButtonBox $tb.bbox -spacing 0 -padx 1 -pady 1] $bbox add -command openfile \ -highlightthickness 0 -image [Bitmap::get openfold] -takefocus 0 -relief link \ -borderwidth 1 -padx 1 -pady 1 \ -helptext "Open" $bbox add -command savefile \ -highlightthickness 0 -image [Bitmap::get save] -takefocus 0 -relief link \ -borderwidth 1 -padx 1 -pady 1 \ -helptext "Save" # Display the toolbar pack $bbox -side left -anchor w # Determine window area set hw [.mf getframe] # Text area with scroll bars ScrolledWindow $hw.sw text $hw.sw.t $hw.sw setwidget $hw.sw.t # Display text area pack $hw.sw -fill both -expand yes # Assign open and close functions to Ctrl-O and Ctrl-S bind . openfile bind . savefile