next up previous contents index
Next: Button Up: Glish/Tk Previous: Introduction


  The most basic widget in Glish/Tk is the frame widget. Frames are used to group other Tk widgets and are the parent of most other widgets in Tk. Frames are the basis for layout specification in Glish; they are used to position and group multiple widgets, and they are used to insert space into the GUI layout. Frames can be nested arbitrarily.

Here is a simple Glish/Tk example which creates a number of frames:

    f := frame(side='left')
    rec := [=]
    for (i in "raised sunken flat groove ridge")
       rec[i] := frame(f,relief=i)
In this example, f is set to be a toplevel frame which simply means that it has no parent and thus, is a stand-alone window. The frame function is used to create frames. In this case, we have specified only one parameter, side. By default, frames arrange other widgets from top to bottom, i.e. the default value for side is 'top'. By specifying 'left' here, we are telling the frame to pack children widgets from left to right.

A record is created which will be used to hold the other frames which will be created. The loop loops through each of the different Tk relief styles. The final assignment assigns a frame to elements of the record. The first parameter to frame() is an optional parent, and in this case, the parent for these frames is f. Another optional parameter for frames is relief. It specifies the edge relief of the frame. The default relief is 'flat'.

The window which is generated by this simple script is shown in Figure 10.1.

Figure 10.1: Frame

It shows each of the five different reliefs available for the Tk widgets. In this example, the frames are the children of another frame, and they are packed in the parent frame horizontally.

Frames have a number of other optional parameters, and Table 10.2 lists these options.


Parameter Default Values Description
parent F widget parent of the frame
relief 'flat' 'flat' 'ridge' 'raised' 'sunken' 'groove' border relief
borderwidth 2 dimension width of the border
side 'top' 'top' 'left' 'right' 'bottom' direction for child placement
padx 0 dimension horizontal padding
pady 0 dimension vertical padding
expand 'both' 'both' 'none' 'x' 'y' frame expansion when resized
background 'lightgrey' X color the background color
width 70 dimension default width of empty frame
height 50 dimension default height of empty frame
cursor '' X cursor name cursor displayed in frame
title 'glish/tk' string string displayed by window manager
icon '' path path to xbitmap file
Table 10.2: Frame Construction Parameters


In addition to specifying frame attributes at construction time, frames accept events which can be used to modify frame characteristics. For example, it may be important to change the cursor for a frame to indicate things like the application is busy so the user must wait, continuing the example above:

After this statement, the ``watch'' cursor will be used whenever the user enters the frame with the mouse. All Glish/Tk widgets accept and generate events. Table 10.3 lists the events which frames accept.


Event I/O Values Description
backgroundtex2html_wrap_inline15708 X color change background color
bind tex2html_wrap_inline15708<X> <G> associate Xevent <X> with Glish event <G>
borderwidthtex2html_wrap_inline15708 dimension change border width
cursor tex2html_wrap_inline15708 X cursor name change the cursor for this frame
disabletex2html_wrap_inline15708 disable all widgets within frame, must be balanced by enable
enabletex2html_wrap_inline15708 enable all widgets within frame, must be balanced by disable
expand tex2html_wrap_inline15708 'both' 'none' 'x' 'y' change the resizing behavior
fontstex2html_wrap_inline15710 get all of the available fonts as a string
grab tex2html_wrap_inline15708 'global' 'local' change focus to this frame
icontex2html_wrap_inline15708 path change the icon of the toplevel frame
killed tex2html_wrap_inline15710 indicates frame was deleted by user
maptex2html_wrap_inline15708 make the toplevel frame visible
padx tex2html_wrap_inline15708 dimension set horizontal padding
pady tex2html_wrap_inline15708 dimension set vertical padding
release tex2html_wrap_inline15708 release a grab on this frame
relief tex2html_wrap_inline15708 'flat' 'ridge' 'raised' 'sunken' 'groove' change border relief
resize tex2html_wrap_inline15710 old and new size indicates frame was resized by user
side tex2html_wrap_inline15708 'top' 'left' 'right' 'bottom' direction for child placement
unmaptex2html_wrap_inline15708 hide the toplevel frame
Table 10.3: Frame Events


It is important to note that sending a global grab event to an empty frame is a sure way to lock up your X session. This is because there is no way to release the grab.  

next up previous contents index
Next: Button Up: Glish/Tk Previous: Introduction

Thu Nov 13 16:44:05 EST 1997