Tcl-Tk Code Examples

web links and locally-stored
(preserved) code examples

Home > RefInfo menu > Computer Topics menu > This Tcl-Tk Code Samples page

! NOTE ! Many more code samples are available at the Tcler's Wiki (
Use the 'Search' entry field on the left of each page.
Enter keywords related to your topic of interest.


Below are links to samples of Tcl-Tk code --- arranged in 'application' groups --- desktop utilities, audio-video, 2D plotting-drawing, 3D graphics, socket scripts, Expect scripts, etc.

You can use the table-of-contents below to go directly to code samples in these category-groups. OR you can simply scroll down this page to spot samples of interest.

Alternatively, you can use the 'Find text' option of your web browser to look for keywords on this page. For example, if your were looking for examples of creating widgets with rounded corners, you could search for 'rounded'.

    UPDATE 2017:

    Since this web page was assembled in 2009, some sites have accumulated a rather large collection of code of Tcl-Tk scripts that provide many useful code examples, such as:

    More web sites offering Tcl-Tk code are presented in a 'Code Samples' section of a Tcl-Tk Links page on this site.

    I leave this page intact, in case some of the links below offer useful samples of code that are not easily found via other web pages or via web searches.

    This page preserves some code that may be lost when web sites go dead.

    Speaking of 'preservation' ... here is a web page (on this site) that preserves some Tk GUI images of the 1985 to 2008 era.

How the code samples are presented :

For most code samples, a copy of the code is preserved on this web site. Click on the link named 'Local Code text' to see the text file. Then click on the Back button of your browser to return to this page.

Also, for most code samples, there is a link to the original external web page that provided the source code. Click on the link named 'Code Reference link' to go to the external web page.

Over a period of months or years, the original web sites and web pages vanish, so (because that lesson has been learned many times over) an image of the code is preserved on this web site --- in a plain-text file.

In some cases, the code is later improved or corrected --- by the original author or by reviewers of the code. Sometimes those improvements or corrections or enhancements will be documented on the external link(s) provided. Or, you can do a web search, with key words describing the code (or using actual code fragments), to see if there are updates to the code, available on the web.

(Very) Brief background on Tcl-Tk :

For some info on John Ousterhout (pronounced OH-stir-howt), who created the Tcl-Tck scripting language to help him and his electrical engineering students execute class projects more efficiently and rapidly, see the Wikipedia page on Ousterhout.

A lot of support for Tcl-Tk on-going development comes via Activestate, a Canadian company.

The main web site for Tcl-Tk has moved around over the years --- through organizations such as University of California Berkeley, Sun Microsystems, Scriptics, Ajuba --- and, for quite a few years now, seems to have established a home at

A fairly comprehensive trace of the development of Tcl-Tk, through these organizations, is seen on this page.

Sources of Tcl-Tk code samples :

Many instructive code samples are available through the Tcl-Tk wiki site, However, a lot of the code there is 'demo code', not code for 'full-fledged applications'.

Since many Tcl-Tk scripts start off with a call to the 'wish' interpreter, one way to find code samples is to do web searches on keyword strings such as

  • "bin/wish" button label
  • "bin/wish" canvas bindtag
  • "bin/wish" frame
  • "bin/wish" binding
  • "bin/wish" proc
  • "bin/wish" ttk
  • "bin/wish" socket

That is how many of the following code samples were found.

Format of the code :

The code samples are presented as they were on the page where the code was found. However, in some cases, you may have to add a lead-off statement like

    #!/usr/bin/wish   or   #!/usr/local/bin/wish
to call on a Tcl-Tk interpreter to execute the code.

I personally like to follow a standard organization of my code, so that I know where to look for certain kinds of code blocks.

The organization I like to follow whenever possible, with Tk scripts, is

  • Define the GUI (frames, then widgets throughout the frames, basically going left to right, top to bottom)

  • Define bindings, if any

  • Define procs, if any

  • If needed, provide additional GUI initialization and data initialization --- by calling procs or via added Tcl-Tk code.

A more detailed description of this code organization is at the page titled A Canonical Structure for Tk Code --- and variations.

In contrast to that 'canonical technique', in the following code examples, you may find the GUI-defining code almost anywhere, from top to bottom of the code.

Tcl-Tk tutorials :

There are many web sites that provide tutorials for Tcl-Tk. Someday I may provide a web page of such sites. Unfortunately, many such sites go dead quite rapidly.

In the meantime, here are a couple of pages (updated in 2009) at that contain links to some tutorials --- page 20796 and page 1304. And here is an online Tcl (not Tk) tutorial at the site.

A problem with tutorials is that they often contain many code 'snippets' but not many complete code samples that accomplish very much. To accomplish much, they would have to be too long for a tutorial.

The code samples below are, for the most part, too large for tutorials. But they have much to offer in the way of examples of working (de-bugged) code for Tcl-Tk developers 'of all stripes'.

Table of Contents:   (sections of this page, below)

Some of these categories may overlap --- for example, some 2D plotting applications could also be categorized as desktop apps. For simplicity, each example is placed in only one category.

End of Table of Contents. Start of code samples.

'External' Links to more code examples :

There are many samples of working Tcl-Tk code at the Tcler's Wiki site ( Some of those samples are complete mini-applications. Some of those samples are above.

Here are a few links to other samples at

Some Tcl-Tk code 'snippets' and mini-apps :

Some large-scale Tcl-Tk code to study (available as compressed files) :

3D code sources :

Ways to extend Tcl-Tk :

And here are some other possible sources of Tcl-Tk code.

Bottom of the Tcl-Tk Code Examples page.

These code samples provide Tcl-Tk beginners (and experienced developers) examples of Tcl-Tk code that use features, bindings, procedures, widgets, etc. that they may not be experienced in using. Hence these are time-savers.

To return to a previously visited web page, click on the
Back button of your web browser a sufficient number of times.
OR, use the History-list option of your web browser.
OR ...

< Go to Table of Contents, above. >
< Go to Top of Page, above. >

Page was created 2009 Mar 19.
Page was changed 2010 Mar 28. (Format was changed slightly.)
Page was changed 2015 Oct 04. (Re-formatted somewhat.)
Page was changed 2017 Aug 29. (Added 'UPDATE 2017' section.)