Introduction to Tk

As mentioned above, Tcl is designed to be extensible. The first and most basic Tcl extension is Tk, an X11 toolkit. Tk provides the same basic facilities that you may be familiar with from other X11 toolkits such as Athena and Motif, except that they are provided in the context of the Tcl language. There are C bindings too, but these are seldom needed—the vast majority of useful Tk applications can be coded using Tcl scripts.

If it has not become obvious already, it is worth noting at this point that Tcl is one example of a family of languages known generally as "Very High Level Languages", or VHLL's. Essentially a VHLL raises the level of programming to a very high level, allowing very short token streams to accomplish as much as would be required by many scores of the more primitive actions available in a basic HLL. Consider, for example, the basic "Hello World!" application written in Tcl/Tk.

	#!/usr/local/bin/wish -f

	button .hello -text "Hello World!"  -command "destroy ."
	pack .hello

That's it! That's all there is to it. If you have ever programmed X using a traditional toolkit such as Athena or Motif, you can appreciate how amazingly much more convenient this is. If not, you can either take our word for it that this is 20 times less code than you would need to use a standard toolkit, or you can go write the same program in one of the usual toolkits and see for yourself...

We cannot hope to provide a thorough introduction to Tk programming in this section. Instead, we will just say that immensely complex applications can be constructed merely by programming in exactly the way shown in the above script. By writing more complex scripts, and by utilizing the additional widgets provided by Tk, one can create beautiful, extensive user interfaces. Moreover, this can be done in a tiny fraction of the time it takes to do the same work in a conventional toolkit. Literally minutes versus days.

Tk provides widgets for labels, buttons, radio buttons, frames with or without borders, menubars, pull downs, toplevels, canvases, edit boxes, scroll bars, etc.

A look at the interface provided by the PLplot Tk driver should help give you a better idea of what you can do with this paradigm. Also check out some of the contributed Tcl/Tk packages available at harbor. There are high quality Tk interfaces to a great many familiar Unix utilities ranging from mail to info, to SQL, to news, etc. The list is endless and growing fast...