next up previous
Next: Widget paths Up: An introduction to Previous: Binding actions to

Frames

A frame can be thought of as a window within a window. It acts as a container of other widgets. Frames are needed because the mechanism of the Tk packer alone is too limited to even create user interfaces of little complexity. For example, the application in figure 3 can not be created with the packer only (left as an exercise for the reader).

  
Figure 3: Example of using frames

The commands used for creating this application are:

frame .f1 -relief raised -borderwidth 3
button .f1.b1 -text "Button 1"
pack .f1.b1 -side top
button .f1.b2 -text "Button 2"
pack .f1.b2 -side bottom
pack .f1 -side left

frame .f2 -relief raised -borderwidth 3
button .f2.b3 -text "Button 3"
pack .f2.b3 -side top
button .f2.b4 -text "Button 4"
pack .f2.b4 -side bottom
pack .f2 -side right

A frame is created just like any other widget. The widgets that are to be contained in a frame have the path of the frame prepended to their own path. The widgets within a frame are packed into the frame, the frame itself will be packed in a window.



SE Praktikum
Tue Aug 13 13:33:30 MET DST 1996