Chapter 3. Tk Core Commands

Tk is the most popular extension to the Tcl language. John Ousterhout, the author of Tcl itself, wrote the Tk extension soon after releasing Tcl to the public. Tk is available at http://www.scriptics.com. This chapter covers Version 8.0.

Tk adds many new commands to the Tcl interpreter for writing graphical user interface (GUI) applications. Commands are available to create and lay out several different types of windows, called widgets, bind Tcl scripts to window system events, create and manipulate graphical images, and interact with the window manager and server.

Tk scripting provides an excellent tool for quickly prototyping GUI applications. Programs that take many hundreds of lines of Xlib or Motif C code can typically be done in less than a hundred lines of Tk. Also, no compilation is necessary and almost all aspects can be dynamically reconfigured during runtime. Using the powerful I/O commands of Tcl, it is also easy to add graphical interfaces on top of existing command-line applications.

The Tk extension can be loaded into a running Tcl interpreter by using the command:

package require Tk

on systems supporting dynamic loading. Typically, one runs the program wish, which starts a Tcl interpreter with the Tk extension already loaded.

Get Tcl/Tk in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.