Tcl-Tk Code Examples
web links and locally-stored
! NOTE !
This page provides a 'smattering' of
Tcl-Tk code project examples from the web.
Many code 'demo'/'snippet' samples are available
at the Tcler's Wiki (wiki.tcl.tk).
And 'heftier' code samples are available
via the 'tkGooies' pages at www.freedomenv.com
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 a 'Find text in page' option of your web browser to look for keywords on this page. For example, if you are looking for examples of creating widgets with rounded corners, you could search for 'rounded'.
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 External 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 www.tcl.tk.
A fairly comprehensive trace of the development of Tcl-Tk, through these organizations, is seen on this softpanorama.org page.
Sources of Tcl-Tk code samples :
Many instructive code samples are available through the Tcl-Tk wiki site, wiki.tcl.tk. 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
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
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
A more detailed description of this code organization is at a www.freedomenv.com 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 wiki.tcl.tk that contain links to some tutorials --- page 20796 and page 1304. And here is an online Tcl (not Tk) tutorial at the www.tcl.tk site.
To look for other Tcl-Tk tutorials, you can try a WEB SEARCH on keywords such as 'tcl tk tutorial'.
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:
(links to sections of this page, below)
Tcl-Tk Script Samples for:
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.
Many of the 3D apps require 'tcl3D' (formerly called 'togl') --- a tcl-tk extension to perform Open GL (3D graphics) operations. Some of this code may come from the 'tcl3d.org' site.
END of (locally preserved) CODE SAMPLES.
'EXTERNAL' LINKS TO MORE CODE EXAMPLES :
There are many samples of working Tcl-Tk code (but usually relatively simplistic 'demo' scripts) at the Tcler's Wiki site (wiki.tcl.tk).
Some of those samples are could be considered complete mini-applications. Some of those samples are above.
A few links to other samples at wiki.tcl.tk follow.
Some Tcl-Tk code 'snippets' and mini-apps :
Some large-scale Tcl-Tk code to study
3D code sources :
Ways to extend Tcl-Tk :
To look for even more examples of Tcl-Tk code, you can try a WEB SEARCH on keywords such as 'tcl tk application code gui'. If this search does not satisfy, change some keywords to look for images of a specific kind.
Bottom of this
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.
Page was created 2009 Mar 19.