Previous: Packing
Up: Widgets
Next: Using TCL code to generate widgets
Previous Page: Packing
Next Page: Using TCL code to generate widgets

Using frames to improve packing

Frames are widgets whose main purpose is to contain other widgets - they don't do very much themselves. They are useful for helping to pack widgets into two dimensional layouts.

Suppose we want to create the following layout:

label1   entry1
     label2   entry2
     label3   entry3

This can conveniently be done by defining two frames to contain the two columns, and then packing the frames, as shown below:

frame    .f1
     frame    .f2
     label .f1.label1 -text "Label1"
     label .f1.label2 -text "Label2"
     label .f1.label3 -text "Label3"
     #vertically pack labels
     pack .f1.label1 .f1.label2 .f1.label3
     entry .f2.entry1 -textvariable entrydata1 -relief sunken
     entry .f2.entry2 -textvariable entrydata2 -relief sunken
     entry .f2.entry3 -textvariable entrydata3 -relief sunken
     #vertically pack entry boxes
     pack  .f2.entry1 .f2.entry2 .f2.entry3
     #horizontally pack columns
     pack  .f1 .f2 -side left

Alternatively, three frames packed vertically above each other may be used to contain a single label and entry widget which are packed side by side:

frame    .f1
     frame    .f2
     frame    .f3
     label .f1.label1 -text "Label1"
     entry .f1.entry1 -textvariable entrydata1 -relief sunken
     #pack these two horizontally
     pack  .f1.label1 .f1.entry1 -side left
     label .f2.label1 -text "Label2"
     entry .f2.entry1 -textvariable entrydata2 -relief sunken 
     pack  .f2.label1 .f2.entry1 -side left
     label .f3.label1 -text "Label3"
     entry .f3.entry1 -textvariable entrydata3 -relief sunken
     pack  .f3.label1 .f3.entry1 -side left
     #now pack each frame vertically
     pack  .f1 .f2 .f3

csstddm@brunel.ac.uk
Fri Aug 19 16:55:19 BST 1994