Dr Christian Hicks - Tk/Tcl Resources

Department of Mechanical, Materials and Manufacturing Engineering,
Stephenson Building, University of Newcastle upon Tyne, Newcastle NE1 7RU.

The Tool Command Language "Tcl" was invented by Dr. John Ousterhout. It is an interpreted scripting language which runs on most hardware platforms and operating systems. It has the attraction of being free, it is well documented and widely used. It can be used for any purpose - academic or commercial. It is quite an easy language to learn, but can be used for powerful applications, particularly when it is embedded with other languages such as C or C++. It really comes into its own when it is combined with Tk, its windowing toolkit. This provides a flexible way to produce graphical "front ends" for programs. Tcl plug-ins are available for Netscape Navigator and Microsoft Internet Explorer. These helps make Tcl the language for the internet, since it can run on all main operating system types and popular browsers. Jacl has also been developed which is an implementation of the Tcl interpreter written using Java.

Simple program examples (tested using tk 4.1 and tcl 7.5)

Web links
Clif Flynt's Home Page - lots of useful stuff here
John Ousterhout's Home Page - the guy who developed Tk/Tcl
tkBuilder - a tool for building tk graphical user interfaces (GUIs)
Tcl/Tk Cookbook - a good set of manuals from the Rutherford Appleton Laboratories
Tcl/Tk contributions archive
Tcl/Tk Developers' Exchange - downloads, manuals etc.
TK/Tcl information, tutorials, presentations etc.
Tcl/Tk 8.1.1 ManualTclTutor - a free computer aided learning package
Tcl/Tk tutorial

Windows 3.1, 95, 98,CE and NT Implementations
The first step is to download the software from the Developers' Exchange. You then need a text editor that can produce plain text files which need to have a .tcl extension. A list of suitable editors is provided here. Eric Foster-Johnson maintains a list of frequently asked questions relating to windows compatibility issues. The distribution includes the tcl application called tclsh and the "windowing shell" called wish. If wish is run from the program menu two separate windows come up: the Tk console and a wish window.

Straightforward tcl scripts should be executed in using either tclsh or the Tk Console either by typing the code in directly, or through using the source statement.

e.g. %source d:\users\nch\programs\test.tcl;

The third way to launch a Tcl script is to create a file type association for the extension ".tcl" (or ".tk"). Using the File Manager (or My Computer in Windows 95), create a new file type for .tcl, and add an "open" action. The command for the action should be something like:

"c:\Program Files\tcl\bin\wish83.exe" "%1"
Once you have set up the association, you will be able to double click on script files in File Manager to launch the app. Note that if either the location of wish or the location of the script contains spaces in any of the file names, you must enclose the name in quotes. For example:
"c:\Program Files\tcl\bin\wish83.exe" "c:\Program Files\myscript.tcl"
However, when I tried this I only got the wish window with no wish console, so it seems to be no good for executing straightforward Tcl scripts.

Web Tk-Tcl
Tk-Tcl provides an effective way of providing interactive graphical programs through a clients browser. A plug-in is available from the Developers' Exchange, which works with both Netscape and Internet Explorer. The plugin in based upon "Safe Tk-Tcl" which has a limited set of commands that excluded all functions that would allow hackers to cause damage to the client's machine. Various security policies can be set up by the client to extend the range of commands available. Safe Tcl excludes the following commands:

cd exec fconfigure file grab pwd  and socket

Safe Tk excludes:
bell clipboard grab menu send tk toplevel and wm

Examples of Tk-Tcl and Safe Tk-Tcl scripts will appear shortly.

Ball S., 1999, "Web Tcl Complete", McGraw-Hill, New York, ISBN 0-07-913713-X.
Harrison M and McLennan M, 1998,"Effective Tcl/Tk Programming",Addison Wesley Longman Publishing, ISBN 0201634740.
Foster-Johnson E., "Graphical Applications with Tcl and Tk"
Ousterhout J.K., 1994, "Tcl and the Tk Toolkit", Addison Wesley, New York, ISBN 0-201-63337-X.
Welch B,1999, "Practical Programming in Tcl and Tk", Prentice Hall, ISBN: 0130220280

Visitors since 22nd February 2001

Chris Hicks' Home Page This page was last updated on 1st November 2001 

© Dr Christian Hicks, Department of Mechanical, Materials and Manufacturing Engineering, University of Newcastle upon Tyne