Version 6 of Persistent Tcl and Tk Applications

Updated 2002-09-27 17:20:05

Purpose: document tools and techniques for creating persistent state in Tcl and Tk applications. By persistent state, I mean the ability to have a Tcl/Tk application , at start up, initialize all its variables, widgets, etc. to the value they had at the time of last termination.

This will require the storing of variables in a form they can be reset, recognizing all widgets, their configs and values, etc.

  • plain variables
  • arrays
  • handles (what to do about open file handles, etc.?)(1)
  • procs (defined, renamed, etc.)(2)
  • interps
  • threads
  • widgets

Metakit is one tool.


Relational databases (postgresql, for example) do a good job of keeping track of state. They have been perfected for just such a task...


(1) I'd say only a "persistable" state should be made persistent, i.e. where open files have been closed before (they will be on program termination anyway). To make sure the file is not modified in the meantime, it has to be put on read-only - but even that can be reset by the owner (or root)...RS

(2) Here the proc command would have to be overloaded to save its name argument immediately after each call, so at "pickling" time (I think that's how they call it in Python) you know which procs have been changed. But that can be countered by redefining the proc command. RS


Little known fact -- e4Graph's Tcl binding allows you to define additional methods on a node in Tcl, which are essentially stored procedures. This allows you to store a whole Tcl program in an e4Graph storage. The syntax is very simple:

$node method foo {a b} {list $a $b expr $a + $b}

$node call foo 34 45

==> 34 45 89

Jacob Levy