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
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
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:
f->cursor('watch')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 background X color change background color bind
<X> with Glish event
borderwidth dimension change border width cursor X cursor name change the cursor for this frame disable disable all widgets within frame, must be balanced by enable enable enable all widgets within frame, must be balanced by disable expand 'both' 'none' 'x' 'y' change the resizing behavior fonts get all of the available fonts as a string grab 'global' 'local' change focus to this frame icon path change the icon of the toplevel frame killed indicates frame was deleted by user map make the toplevel frame visible padx dimension set horizontal padding pady dimension set vertical padding release release a grab on this frame relief 'flat' 'ridge' 'raised' 'sunken' 'groove' change border relief resize old and new size indicates frame was resized by user side 'top' 'left' 'right' 'bottom' direction for child placement unmap hide the toplevel frame
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.