Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


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


Frame

The most basic widget in Glish/Tk is the frame widget. The frame widgets group other Tk widgets and are the parent of most other widgets in Tk. They position and group multiple widgets and insert space into the GUI layout forming the basis for layout specifications.

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.

Figure 11.1: Frame
\begin{figure}
\centerline{\psfig{figure=tkframe.eps,scale={0.7}}}\end{figure}

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.

Table 11.2: Frame Construction Parameters
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
newcmap F boolean use private color map?
tlead F widget leader for this popup frame
tpos 'sw' 'c' 'n' 's' 'e' 'w' 'ne' 'nw' 'se' 'sw' location of this popup, relative to tlead
hlcolor '' X color highlight color with focus
hlbackground '' X color highlight color without focus
hlthickness [] dimension hightlight border thickness
visual '' 'staticgrey', 'greyscale', 'staticcolor', 'pseudocolor', 'truecolor', 'directcolor', 'best'11.2 set the visual to be used for all drawing within the frame
visualdepth [] integer bit depth of desired visual

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.


Table 11.3: Frame Events
Event I/O Values Description
background $ \rightarrow$ X color change background color
bind $ \rightarrow$ <X> <G> associate Xevent <X> with Glish event <G>
borderwidth $ \rightarrow$ dimension change border width
cursor $ \rightarrow$ X cursor name change the cursor for this frame
disable $ \rightarrow$ disable all widgets within frame, must be balanced by enable
enable $ \rightarrow$ enable all widgets within frame, must be balanced by disable
expand $ \rightarrow$ 'both' 'none' 'x' 'y' change the resizing behavior
fonts $ \leftarrow$ all available fonts as a string
grab $ \rightarrow$ 'global' 'local' change focus to this frame
height $ \leftarrow$ get current height of frame
hlbackground $ \rightarrow$ X color highlight color without focus
hlcolor $ \rightarrow$ X color highlight color with focus
hlthickness $ \rightarrow$ dimension hightlight border thickness
icon $ \rightarrow$ path change icon of frame
killed $ \leftarrow$ frame was deleted by user
map $ \rightarrow$ make the toplevel frame visible
padx $ \rightarrow$ dimension set horizontal padding
pady $ \rightarrow$ dimension set vertical padding
raise $ \rightarrow$ none or toplevel frame raise frame, just above param if supplied
release $ \rightarrow$ release a grab on this frame
relief $ \rightarrow$ 'flat' 'ridge' 'raised' 'sunken' 'groove' change border relief
resize $ \leftarrow$ old and new size indicates frame was resized by user
side $ \rightarrow$ 'top' 'left' 'right' 'bottom' direction for child placement
title $ \rightarrow$ string set title of frame
unmap $ \rightarrow$ hide the toplevel frame
width $ \leftarrow$ get current width of 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.

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 := F
will 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.


next up previous contents index
Next: Button Up: Glish/Tk Previous: Introduction   Contents   Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15