What is Tk

Brief intro to Tk

The Tk windowing toolkit, written in C, is designed to give the programmer a relatively high level interface to their windowing environment.

Tk is equally available as a windowing toolkit for Tcl, Ruby, Perl, Python. TkDocs has the best overview of how this compares. Tk started life as a Tcl extension.

"Tk" occasionally is used when referring to

  • the programming toolkit, available for many languages
  • 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
  • the Tk extension, which adds a number of new commands to a particular Tcl interpreter

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 8.[0-4], updated to look very similar to Motif, but not using the Motif libraries. Prior to that Tk provides interfaces to the X window system using a Tk specific look and feel. Tk 8.[56] have undergone tweaking so that applications look more like other applications on the platform on which the application is running.

Tk in the Web Browser

Tk applications run on the desktop, not in the browser. Strategically this means Tk apps will become less prevalent if most applications move to web-based software.

2017-12-09 : Check out CloudTk [L1 ] for viewing Tk apps in a browser.

Tk is not universally available for the browser, so programs written in Tk can only really work on the desktop.

  • The TkPlugin is not available for the Mac
  • Where it is available it is largely out of date.
  • There does exist aejaks, a Tk-like bridge to Java-based echo widget set. Programs written in Tk will not work in Aejaks as the widget set is different.
  • In 2000 there was an effort, named proxyTk, Proxy Tk to provide full-Tk in the browser. This effort has ceased.
  • Your best bet is Porting a Tk GUI to A Web Browser, but then it won't work on the desktop
  • In short, Tk is not a universal solution.

Source Code

You can find the source code for Tk at http://sourceforge.net/projects/tktoolkit/ .

History of Tk

Tk was written by John Ousterhout, the creator of Tcl. A PostScript version of the paper where Tk was introduced to the world can be found at ftp://www.tcl.tk/pub/tcl/doc/tkUsenix91.ps .

The PostScript for slides used by Dr. John Ousterhout during USENIX tutorials on Tcl and Tk can be found at ftp://www.tcl.tk/pub/tcl/doc/tut.tar.Z .

Tk Widget Set

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.

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.

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.

To understand the model for how GUI applications are built and operated see TkDocs.

See Beginning Tk for more information.


See Tk

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

Alternate Widget Sets

See Alternate widget sets

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