Getting Started | Documentation | Glish | Learn More | Programming | Contact Us |
Version 1.9 Build 1556 |
|
Here is a simple Glish/Tk example that 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 a toplevel frame. Toplevel frames are stand-alone windows which have no parent. The frame function creates the frames. In this case only one parameter is specified, side. By default, frames arrange other widgets from top to bottom, i.e. the default value for side is 'top'. By specifying 'left' here, the frame packs children widgets from left to right.
A record is created and used to hold the other frames they are
produced. 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 11.1.
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 11.2
lists these options.
|
In addition to specifying frame attributes at construction time, frames accept events which are used to modify frame characteristics. For example, you may want to change the cursor for a frame to indicate the application is busy so the user must wait. Continuing the example above:
f->cursor('watch')After this statement, the ``watch'' cursor is used whenever the user enters the frame with the mouse. All Glish/Tk widgets accept and generate events. Table 11.3 lists the events which frames accept.
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.
In addition to toplevel frames and nested frames, it is also possible to create popup or transient frames. These frames are created whenever you need a toplevel frame which does not have the window manager decorations. These transient frames are created relative to some other widget. For example, this
f := frame() b := button(f) b->bind('<Enter>','enter') b->bind('<Leave>','exit') whenever b->enter do t := frame(tlead=b,tpos='se',background='blue') whenever b->exit do t := Fwill create a button, and whenever the cursor enters the button, it will pop up a blue frame. When the cursor exits the button, it will pop down the frame. The position of the transient frame is defined relative to another widget, here b, which is passed as the tlead parameter. The tpos parameter specifies where in relation to the tlead widget the frame should be positioned, in this case the southeast corner. When the tlead widget is moved, any transient frames which are associated with it move too. These transient frames are useful for things like popup help.