Practical Programming in Tcl & Tk, Third Edition By Brent B. Welch
Table of Contents
Chapter 27. Buttons and Menus
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.
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
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 27-4 summarizes the complete set of menu operations. In the table, $w is a menu widget.
Table 27-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.