This page last updated 13 December 1997

Waihekepaul's Tcl/Tk Page of Horizontal Rules

You may have come from
The Main Tcl page
This page provides examples of how you can enliven your page with simple horizontal rulers made out of Tcl/Tk commands.

This music has been ommitted
Thank you J S Bach for Bwv1052 mov 2.
Midi file copyright of Paul Nash 1996.
Permission granted to copy for non-commercial use only.

The FRAME command

The frame command is the most simple widget command - when you are taught about Tcl/Tk, the frame command is just mentioned briefly because it is considered too simple to say much about. BUT, it is very useful for our purposes. In fact it is quite remarkable.

All the examples will show the Tcl/Tk code that produce the given images. Tcl script can now be written directly into your .html file by using the <EMBED TYPE='application/x-tcl' SCRIPT='.....' > HTML statement. If you have a Tcl script that you wish to reuse on the same page or different pages you can put it in a seperate file and use the SRC= option instead of the SCRIPT= option. As some Web Hosts do not yet allow .tcl files on their systems (yeah, like Geocities who forgot to crawl into the Ark) you can give your tcl files a .txt type and retain the TYPE='application/x-tcl" option. But if the files are held as .tcl you dont need the TYPE= option.

First here are two examples from the main Tcl/Tk page.

pack [frame .f -background blue -width 600 -height 15 -relief raised -borderwidth 5]

pack [frame .f -bg yellow -width 600 -height 30 -relief groove -bd 10 -highlightthickness 5 -highlightbackground red]
These two examples illustrate a number of points. Both are minute programs and as such are called "Tclets". The inventor of Tcl chooses to say "Tcl" as "tickle". So "Tclets" is pronounced "ticklets". Enuff said. A Tclet is a Tcl program that is typically executed by a safe-Tcl interpreter on a browser. Both examples consist of one Tk statement, a 'pack [frame ....]' statement. This is actually two statements, a "frame" and a "pack" statement combined into one statement. In "pretty" tcl scripts they would be on seperate lines. So I offer my apologies to professional tcl scripters for using this shorthand.

The frame statement describes the image while the pack statement arranges for the image to be shown on the screen. The ".f" is the name I have given to each frame. Because these are two seperate Tclets they can both have the same name. Widget names start with a "." which represents the root window, much as "/" at the beginning of a filename represents the root directory. And, yes, widgets have an hierarchical structure, just like directory structures. Indeed the "frame" widget is similar in function to a file directory. It is normally used to contain other widgets, including sub-frames. But here we are using frames to add colour to the page.

After the ".f" the frame command consists of pairs of words, an option name starting with a "-" followed by an option value. A very few of the option names have abbreviations "bd" for "borderwidth" and "bg" for "background". These are special abbreviations for these two particular options. The numbers are in pixel units, like HTML.

The colours are the standard colour names, or you can use the #RRGGBB hexadecimal format.

The relief option can be "raised" "sunken" "groove" "ridge" and the default "flat".

If you think of using a flat frame just to space things out on your page by using a colour the same as your page background, just use the TABLE tag instead. Also, you cannot attach A tags to Tcl windows on your page (yet).

To see more details of how to use simple frames try playing with this painter.

Here are some more simple bars which use the highlightbackground type.

While what has been shown so far is useful, there is a lot more that can be done with frames. They can be placed side by side, or nested. The rainbow rule and flag are examples of frames placed side by side.

foreach i {orangeRed1 orange yellow green royalBlue1 darkorchid1} {
	frame .$i -background $i -width 800 -height 5
	pack .$i  -side top
As well as packing frames down, you can pack frames across. Here are some examples of a simple frame stacked sideways. It is possible to use the reliefs to give interesting effects.

The same painter as above can be used to construct a ruler out of frames stacked across the page.

Frames can also be nested inside other frames as well as beside them. Here is an example:

for {set i 0} {$i<30} {incr i} {
  frame .f$i -bg grey -bd 5 -relief raised 
  frame .f$i.g -bg grey -width 10 -height 10 -bd 5 -relief groove 
  pack .f$i .f$i.g -side left
The above example uses more of the power of Tcl, using the "for" command, string substitution, assignment and increment commands. Here is a painter for single nested frames.

Here are some more examples generated by this painter. They can be quite delicate.

As you can see, the rulers can be constructed with an increasing complexity of frame arrangement and within each frame arrangement there is an increasing number of ways you can modify and personalise your border. In the greek border above you could try swapping the raised and groove relief options, and perhaps try -bg colors like gold1 and gold2. You do not have to change the program structure of the Tclet, just play with all the options. Here is the next level of complexity and a painter for them.

The last useful thing we can do with a single element is to stack them in rows as well to make a grid. I will do an example later. But from here on the next step in complexity is to alternate image elements.

Alternating Frames

With alternating frames all sorts of new possibilities present themselves. You can try alternating colours including your HTML page background colour.

Here is a painter that will help you design these.

Here is an example of an alternating doubly nested pattern. Alternating frames can be extended into a grid pattern to acheive checkerboard effects. As an example a large array of tiny frames - result a checkered flag for racing enthusiasts.

Here is another painter which generalises this idea - have fun:)

By now the variety of borders that can be generated using Tk frames can be appreciated. But we have only been using horizontal rules. These frames can also be used vertically, or a combination of horizontal and vertical.
There are a wealth of possibilities!

Main Tcl page 1997
This page hosted by GeoCities Get your own Free Home Page