Version 34 of What is Tk

Updated 2009-05-15 15:55:30 by LV

Purpose: Brief intro to Tk

Tk is a Tcl extension, written in C, designed to give the user a relatively high level interface to his or her windowing environment. You can find the source code for Tk at http://sourceforge.net/projects/tktoolkit/ .

On a Macintosh, Tk provides interfaces to the MacOS windowing system. On Microsoft Windows 95/98/NT/2000/2003/XP/Vista/..., Tk provides interfaces to the Microsoft windowing system. On the other platforms where Tk is available, Tk provides interfaces to the X window system using a Tk specific look and feel, designed initially to look uniquely Tk, then, in Tk 8.[0-4], updated to look very similar to Motif, but not using the Motif libraries.

Tk was written by John Ousterhout, the creator of Tcl. A PostScript version of the paper introducing Tk to the world can be found at ftp://www.tcl.tk/pub/tcl/doc/tkUsenix91.ps . The PostScript for slides used by Dr. Ousterhout during USENIX tutorials on Tcl and Tk can be found at ftp://www.tcl.tk/pub/tcl/doc/tut.tar.Z .

Tk allows you to create, manage, and manipulate widgets, rectangular areas on the screen with various features, from which you can build quite powerful GUIs with little effort. Some examples of widget types are:

  • button (with text or image): executes a command when clicked
  • label (with text or image): shows info, can be updated from a variable
  • text widget: holds text in various fonts, colors, styles; can also hold embedded images and widgets; can wrap and/or be scrolled
  • canvas: holds graphic objects (including text, images, widgets)
  • listbox: holds text lines from which to select
  • scrollbar: controls the display within another widget through the slider and the 2 arrows at each end.
  • scale: horizontal or vertical, allows setting a numeric value [Isn't scale rather similar to scrollbar, though? Perhaps menu would be a better example of showing the breadth of the widget concept.]

For sample images, look at Widgets in the initial Tk package.

[However, listing the widgets says very little about what Tk is; every GUI toolbox has a set of built-in widgets. More interesting would be to explain the model for how GUIs are built and operated: the window hierarchy, geometry managers (part done below), events, binding scripts, bindtags, ...]

In Tk, the programmer only needs to specify how the widgets are arranged in a window (layout); the geometry of widgets is dynamic, so they can respond automatically both to changes in layout and to user resizing of windows.


On the titular theme, "Tk" occasionally is used when referring to

  • the Tk extension, which adds a number of new commands to a particular Tcl intepreter
  • the Tk C library, which is available for applications built in such languages as C, Perl, and so on
  • the wish interpreter which instantiates a Tk console

See Beginning Tk for more information.


There are many online Tcl and Tk tutorials, perhaps starting with an overview of tcl and tk; Tcl Tutor is quite popular as a desktop computer aided instruction application for the base Tcl language.


Also of interest might be Alternate toolkit bindings, Common Tk Error Messages and Possible Explanations, Alternate widget sets


See What is Tcl for information about the initial language that formed a basis for Tk.