Introducing Tcl/Tk


I am the System Administrator at City University's Central Computing Service where I help run about 100 Sun Unix workstations. For a long time I had felt that some kind of ``scripting'' language for programming X-windows would be useful. About three years ago I heard about something called *the visual Korn Shell*. I enquired of AT&T how much this would cost, but at 20,000 (I think that was the educational price) it was clearly not *my* idea of an educational price!

Then last year I installed Linux on my notebook. I acquired a copy of the SLS X11 distribution and started reading the README `one-liners' which describe the various ``packages'' that form the distribution. Something caught my eye---Tk, described as a ``widget script language for X11''. Could this be the Holy Grail?

Well, yes, it turned out to be just what I wanted. And I'm certain what many thousands of others have wanted too.

What Exactly is Tcl/Tk?

Firstly let me explain the name. Tcl/Tk is really a fusion of two separate pieces of software; Tcl and Tk. [Incidentally, ``Tcl'' is pronounced ``tickle''.] Tcl is a basic scripting language which provides all the primatives of a programming language. It has variables, flow control, procedures (sub-routines), file I/O, and access to Unix processes. [Experts will have to forgive my over-simplification of exactly what Tcl is.]

Tk is a ``ToolKit'' (just another name for a library of Useful Routines) which provide GUI primatives (called ``widgets'') such as buttons, entry-boxes and scroll-bars. These are programmed to have the Motif `look & feel'---though you don't need Motif to install Tcl/Tk. The really neat thing about Tk is that to access its widgets you use high-level commands---all encapsulated in the Tcl language. Being a script, Tcl/Tk programs are not compiled. This alone speeds up development time.

For example, here's a simple program to create a button, which when you click on it will terminate the program (OK, so not too useful, but then neither is ``printf( "hello, world\n" );'' )

button .b -text "press me" -command {exit 0}
pack .b

Programming Tcl/Tk is Fun!

Since last September I have been using Tcl/Tk to create a few new X11 tools for our Unix service at City University. I've also come across many superb examples of what can be done with this truely versatile programming system. Here's my favourite Tk programs; I know of Tk interfaces for both mail and news and a drawing program called picasso.

My own contributions are much more modest, but (to me at least) demonstrate the power that the system has. So far I've created simple tools to interface to the Unix `passwd' and lpr/lpq/lprm commands.

Pwdtool allows the user to enter the new password and two further entry-boxes are provided for the new password. Being a graphical program novice users can be `guided' by messages which tell them what to do next.

The print-tool provides a simple file-selection window in which the user can pick a file to print. After printing they can choose to monitor the queue and watch as their job moves up to the top. They can delete their job by clicking on the entry in the queue.

Want to know more?

Get yourself a copy of `Tcl and the Tk Toolkit' by John K. Ousterhout (the author of the software). The book is published by Addison-Wesley, ISBN 0--201--63337--X, priced 27.95.