User Interface Development Tool: Tcl/Tk

 

[ lecture notes | CSC 397 | Pete Sanderson | Computer Science | SMSU ]


Table of Contents

Origins
Tcl characteristics
Tk characteristics
Procedure for preparing demo
Hello world in Tcl/Tk with variations
Packing using geometry manager
The ExecLog example


Resources

Practical Programming in Tcl and Tk 2nd Edition, by Brent Welch
Scriptics ("The Tcl Platform Company") provides definitive Tcl web resource
Sun Microsystems also supports Tcl/Tk
MI/X is a free X server for Mac or Windows from MicroImages..


Origins 

TCL = Tool Command Language

TK = Tool Kit

Return to the Top   


TCL characteristics

Return to the Top   


TK characteristics

 

A sampling of Tk widgets:

frame

Container widget used with geometry managers

button

Command button

radiobutton

One of a set of radio buttons linked to variable

menu

Creates a menu

canvas

Supports lines, boxes, arcs, polygons, widgets, etc

label

Read-only one-line label

entry

One-line text entry widget

message

Read-only multi-line text

scrollbar

Scrollbar linked to another widget

scale

Scale widget to adjust value of a variable

Return to the Top   


Procedure for preparing demo

MI/X is a free X server for Mac or Windows from MicroImages. As of October 1998, the Windows version is X11R5, the Mac version is X11R6. Thanks to Jeff Peck for providing this URL.

In the X world, server is local and client is remote. In the demo configuration, server runs on the Gateway (WinNT), client runs on csc.smsu.edu.

Procedure to run the demo is:

Return to the Top   


Hello World in Tcl/Tk with variations

Basic:

button .hello -text Hello \
-command {puts stdout "Hello, World!"}
pack .hello -padx 20 -pady 10

 

Variation on code (does not affect display):

set theButton .hello
button $theButton -text Hello \
-command {puts stdout "Hello, World!"}
pack $theButton -padx 20 -pady 10

 

Variation to show dynamic attributes:

button .hello -text Hello \
-command {.hello config -text Goodbye! \
-command exit}
pack .hello -padx 20 -pady 10

Return to the Top   


Packing using geometry manager

(chap 12 in Welch first edition, chap 20 in second edition)

Return to the Top   


The ExecLog Example

An interface for entering Unix commands into text entry field with output displayed in separate scrolling text window. Demonstrates a number of the techniques described above, and then some. Primary frame has two child frames: one contains the text entry field and two buttons ("Run it" and "Quit"); the other contains the text output window along with its scrollbar. This is example 19-1 from Welch second edition (example 11-1 from first edition).

Return to the Top  


[ lecture notes | CSC 397 | Pete Sanderson | Computer Science | SMSU ]


Last reviewed: 15 October 1998

Peter Sanderson ( pete@csc.smsu.edu )