[ Team LiB ] Previous Section Next Section

Manipulating Menus and Menu Entries

There are a number of operations that apply to menu entries. We have already introduced the add operation. The entryconfigure operation is similar to the configure operation for widgets. It accepts the same attribute-value pairs used when the menu entry was added. The delete operation removes a range of menu entries. The rest of the operations are used by the library scripts that implement the standard bindings for menus.

graphics/common_icon.gif

A menu entry is referred to by an index. The index can be numerical, counting from zero, or symbolic. Table 30-3 summarizes the index formats. One of the most useful indices is a pattern that matches the label in the menu entry. The pattern matching is done with the rules of string match. Using a pattern eliminates the need to keep track of the numerical indices.

Table 30-3. Menu entry index keywords

index

A numerical index counting from zero.

active

The activated entry, either because it is under the mouse or has been activated by keyboard traversal.

end

The last menu entry.

last

The same as end.

none

No entry at all.

@ycoord

The entry under the given Y coordinate. Use @%y in bindings.

pattern

A string match pattern to match the label of a menu entry.

Table 30-4 summarizes the complete set of menu operations. In the table, $w is a menu widget.

Table 30-4. Menu operations

$w activate index

Highlights the specified entry.

$w add type ?option value? ...

Adds a new menu entry of the specified type with the given values for various attributes.

$w cget option

Returns the value for the configuration option.

$w clone

Makes a linked copy of the menu. This is used to implement tear-offs and menu bars.

$w configure ?option? ?value? ...

Returns the configuration information for the menu.

$w delete i1 ?i2?

Deletes the menu entries from index i1 to i2.

$w entrycget index option

Returns the value of option for the specified entry.

$w entryconfigure index ?option? ?value? ...

Queries or modifies the configuration information for the specified menu entry.

$w index index

Returns the numerical value of index.

$w insert type index ?option value? ...

Like add, but inserts the new entry after the specified index.

$w invoke index

Invokes the command associated with the entry.

$w post x y

Displays the menu at the specified coordinates.

$w postcascade index

Displays the cascade menu from entry index.

$w type index

Returns the type of the entry at index.

$w unpost

Unmaps the menu.

$w yposition index

Returns the Y coordinate of the top of the entry.

    [ Team LiB ] Previous Section Next Section