LINUX - TCL PROGRAM EXAMPLE 1

10/4/97

TCL is a script language for use in XWindows. The TCL program below is the start of a program development tool and demonstrates the use of text, label, and button widgets in a frame.

We need a decent xwindows text editor
Make the program fte

Create a file named "progtool.tcl" with the contents shown in the box:

proc exec_cmd {command} {
# eval handles the details of separating the command into its elements
eval exec $command &
}

proc edit_file { } {
# "textedit" is an XWindows text editor -
# adding "progtool.tcl" opens up the TCl file within "textedit" global progname
exec_cmd "textedit progtool.tcl"
}

#
# Main Program
#
# set window manager values
# the geometry forces the upper left corner of the frame to x=7, y=84.
# Skipping this allows the frame to be placed before opening.
wm geometry . +7+84
# "title" is the text displayed in the top of the frame.
wm title . "Programmer's Tools"

#
# Frame to hold everything
#
set back lightblue
frame .frame -relief raised -bd 2 -bg $back
.frame config -cursor top_left_arrow

#
# Display some text using a label widget
#
label .frame.label -text "Program:" -relief flat -padx 8

# Edit
# Note use of braces, not quotes to avoid substituting now.
# use YELLOW just to be different
button .frame.edit -text "Edit" -command {edit_file} -padx 8 -bg yellow

#Man Pages
#note the use of the backslash "\" to continue a command on the next line button .frame.man -text "Man Pages" \ -command {exec_cmd "/usr/bin/X11/xman -notopbox -bothshown"} -padx 8 -bg green

# Exit program
button .frame.exit -text "Exit" -command { exit } -padx 8 -bg $back

#pack buttons in order - a button will not appear until it is packed
pack .frame.label .frame.edit .frame.man -side left -fill y
# Pack exit button with extra space to avoid accidental exiting
pack .frame.exit -padx 28 -side left -fill y
pack .frame

proc is a tag for a procedure or subroutine. The procedures here are
exec_cmd which is used to pass parameters to the exec command and
edit_file which is used to invoke textedit which is a nice text editor for XWindows
While in textedit use the right mouse button while selecting the buttons at the top of the display.

back is a variable used to hold a value for the background color. Note the references to $back throughout the program.

button is followed by the name of the button (and the frame that contains it) with parameters for a label (-text "Edit"), its command (command {edit_file}), and its background color (-bg $back).

pack causes the button to be displayed.
More information is available on the man pages for button, eval, frame & label.

Open a shell in XWindows, change to the directory containing PROGTOOL.TCL, and type "wish8.3 progtool.tcl"

wish is the TCl interpreter.