An Introduction To Embedded Tk (page 2 of 32)

[Next Page][Table of Contents]

1 Embedded Tk

If you've ever tried to build a large-scale, compute-intensive, or commercial application using Tcl/Tk, you probably had a difficult time of it. A pure Tcl/Tk script is terrific for writing small programs or for prototyping, but it is often inadequate for really big problems. This is due to several factors:

The usual way to avoid these troubles is to code in C or C++ rather than Tcl/Tk. C is fast and well-structured. Compiled C code is difficult for users to read. And statically-linked C programs will run on any binary-compatible computer, independent of other software.

But programming a graphical user interface in pure C is time-consuming and error-prone. The job can be made somewhat easier by using Tcl/Tk's C interface, and having your C program call the Tcl/Tk library routines directly. Many people have done this, some successfully. The task is still tough, though, because unlike its scripting language, Tcl/Tk's C interface is not easy to use. Properly initializing the Tcl/Tk interpreter takes skill and finesse, and calling the interpreter from C is a dull chore.

And so the problem remains: Do you go for the speed and structure of C or the power and simplicity of Tcl/Tk?

The Embedded Tk system (hereafter ``ET'') was created to resolve this conundrum. ET is a simple preprocessor and small interface library that make it easy to mix Tcl/Tk and C in the same program. With ET, you can put a few commands of Tcl/Tk code in the middle of a C routine. ET also makes it very easy to write C functions that work as new Tcl/Tk commands -- effectively allowing you to put pieces of C code in the middle of your Tcl script. These features gives you the speed and structure of C with the power and simplicity of Tcl/Tk. As an added benefit, an application written using ET will compile into a stand-alone executable that will run on any binary-compatible computer, even if the other computer doesn't have Tcl/Tk installed.

[Next Page][Table of Contents]