Tcl-Tk Code Examples

web links and locally-stored
(preserved) code examples

! Preliminary ! More keywords to be added for the samples.
! Also, more code examples are to be collected !

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'.


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 Ousterhout's page at Pac Bell.

In case that page goes dead, you can try 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.

Also, 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, call procs or Tcl-Tk code to initialize ('finish') the GUI.

However, in these 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.

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: (of this page)

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.


DESKTOP Tcl-Tk Script Samples :

< Return to Table of Contents, above. >


AUDIO / VIDEO Tcl-Tk Script Samples :

< Return to Table of Contents, above. >


2D-PLOTTING / DRAWING Tcl-Tk Script Samples :

< Return to Table of Contents, above. >


3D applications & demos - Tcl-Tk Script Samples :

NOTE:
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.

< Return to Table of Contents, above. >


GAMES - Tcl-Tk Script Samples :

< Return to Table of Contents, above. >


SOCKET Tcl-Tk Script Samples :

< Return to Table of Contents, above. >


EXPECT Tcl-Tk Script Samples :

< Return to Table of Contents, above. >


OTHER Tcl-Tk Script Samples - uncategorized (for now) :

< Return to Table of Contents, above. >

END of (locally preserved) CODE SAMPLES.

'External' Links to more code examples :

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

Here are a few links to other samples at wiki.tcl.tk.

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 ...

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

Page created 2009 Mar 19. Page format changed slightly 2010 Mar 28.