tkml is a library written in pure Tcl which makes use of the Itcl object oriented package for providing its users (Tcl/Tk programmers) with a way of easily creating GUIs based on XML text with a pre-defined set of tags and corresponding attributes.
The tkml library is intended to be used as a very simple way to build Tk GUIs and edit them on the fly. It reads XML text containing pre-defined tags and attributes (whose names are identical to the corresponding Tk widget commands) and creates the corresponding GUI elements. Once created, those elements are accessible through Itcl objects which can be used to read/modify their attributes.
With tkml you can concentrate on creating your GUI's content instead of dealing with its programmatic details.
tkml is aimed at Tcl/Tk programmers who want to standardize their GUI creation procedures and make use of templates wherever possible. For those who have used CGI/Javascript and realize their ease of use, they should experience no major difficulties in understanding the concept behind the library and how to use it.
You can save your static or dynamic templates on files (or create them on-the-fly in your code) and then just feed them to the tkml engine which takes care of displaying them. This behavior is similar to the way a Web browser interacts with CGI scripts on the server but, in this case, everything is running on Tcl.
Additionally, you can search for tkml objects by name or ID and query/set their attributes, just like you would using Javascript. For example:
# Load the tkml package # package require tkml # Read the file containing the markup # set handle [open "main-window.xml" "r"]; set xml [read $handle]; close $handle; # Load the markup into the tkml engine # mlObject::loadXml -xml $xml # Find the object containing the 'contents' ID # set contentsObj [mlObject::findObjectById "contents"] # Change its background color # $contentsObj setc background "blue"
In the example above, it is assumed that in file main-window.xml a tag has been defined with the contents ID. After reading the markup from the file and loading it by invoking the loadXml
class method of the top level mlObject
class, the code finds the object whose ID is contents and changes its background color to blue by invoking the setc
(SET Configuration) object method.
Of course, as this is Tcl, your code can create the necessary XML text on-the-fly and feed it to the tkml engine, like in the example below:
# Create new contents # set xml "<frame>\n" append xml " <label height=\"3\">This is the first page of contents</label>\n" append xml "</frame>\n" append xml "<frame><button command=\"show_page_2\">Page 2</button></frame>" # Find the object containing the 'contents' ID # set contentsObj [mlObject::findObjectById "contents"] # Feed it with your XML # $contentsObj setc xml $xml
In this example, a label and a button are created inside different frame widgets so they get displayed on top of each other (otherwise, they would be displayed next to each other). Next, we simply invoke the setc
object method for the xml
attribute and provide it with the XML text.