www.gibmonks.com




  Previous section   Next section

Practical Programming in Tcl & Tk, Third Edition
By Brent B. Welch

Table of Contents
Chapter 27.  Buttons and Menus


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/tip_icon.gif

A menu entry is referred to by an index. The index can be numerical, counting from zero, or symbolic. Table 27-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 27-3. Menu entry index keywords
indexA numerical index counting from zero.
activeThe activated entry, either because it is under the mouse or has been activated by keyboard traversal.
endThe last menu entry.
lastThe same as end.
noneNo entry at all.
@ycoordThe entry under the given Y coordinate. Use @%y in bindings.
patternA string match pattern to match the label of a menu entry.

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

Table 27-4. Menu operations.
$w activate indexHighlights 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 optionReturns the value for the configuration option.
$w cloneMakes 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 optionReturns 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 indexReturns the numerical value of index.
$w insert type index ?option value? ...Like add, but inserts the new entry after the specified index.
$w invoke indexInvokes the command associated with the entry.
$w post x yDisplays the menu at the specified coordinates.
$w postcascade indexDisplays the cascade menu from entry index.
$w type indexReturns the type of the entry at index.
$w unpostUnmaps the menu.
$w yposition indexReturns the Y coordinate of the top of the entry.


      Previous section   Next section
    Top