1Menu(3)               User Contributed Perl Documentation              Menu(3)
2
3
4

NAME

6       Tk::Menu - Create and manipulate Menu widgets
7

SYNOPSIS

9           $menu = $parent->Menu(?options?);
10

STANDARD OPTIONS

12       -activebackground   -background    -disabledforeground -relief
13       -activeborderwidth  -borderwidth   -font     -takefocus
14       -activeforeground   -cursor   -foreground
15
16       See Tk::options for details of the standard options.
17

WIDGET-SPECIFIC OPTIONS

19       Name:     postCommand
20       Class:    Command
21       Switch:   -postcommand
22           If this option is specified then it provides a callback to execute
23           each time the menu is posted.  The callback is invoked by the post
24           method before posting the menu. Note that in 8.0 on Macintosh and
25           Windows, all commands in a menu systems are executed before any are
26           posted. This is due to the limitations in the individual platforms'
27           menu managers.
28
29       Name:     selectColor
30       Class:    Background
31       Switch:   -selectcolor
32           For menu entries that are check buttons or radio buttons, this
33           option specifies the color to display in the indicator when the
34           check button or radio button is selected.
35
36       Name:     tearOff
37       Class:    TearOff
38       Switch:   -tearoff
39           This option must have a proper boolean value, which specifies
40           whether or not the menu should include a tear-off entry at the top.
41           If so, it will exist as entry 0 of the menu and the other entries
42           will number starting at 1.  The default menu bindings arrange for
43           the menu to be torn off when the tear-off entry is invoked.
44
45       Name:     tearOffCommand
46       Class:    TearOffCommand
47       Switch:   -tearoffcommand
48           If this option has a non-empty value, then it specifies a perl/Tk
49           callback to invoke whenever the menu is torn off.  The actual
50           command will consist of the value of this option, followed by a
51           space, followed by the name of the menu window, followed by a
52           space, followed by the name of the name of the torn off menu
53           window.  For example, if the option's is ``a b'' and menu .x.y is
54           torn off to create a new menu .x.tearoff1, then the command ``a b
55           .x.y .x.tearoff1'' will be invoked.
56
57       Name:     title
58       Class:    Title
59       Switch:   -title
60           The string will be used to title the window created when this menu
61           is torn off. If the title is NULL, then the window will have the
62           title of the menubutton or the text of the cascade item from which
63           this menu was invoked.
64
65       Name:     type
66       Class:    Type
67       Switch:   -type
68           This option can be one of menubar, tearoff, or normal, and is set
69           when the menu is created. While the string returned by the
70           configuration database will change if this option is changed, this
71           does not affect the menu widget's behavior. This is used by the
72           cloning mechanism and is not normally set outside of the Tk
73           library.
74

DESCRIPTION

76       The Menu method creates a new top-level window (given by the $widget
77       argument) and makes it into a menu widget.  Additional options,
78       described above, may be specified on the command line or in the option
79       database to configure aspects of the menu such as its colors and font.
80       The menu command returns its $widget argument.  At the time this
81       command is invoked, there must not exist a window named $widget, but
82       $widget's parent must exist.
83
84       A menu is a widget that displays a collection of one-line entries
85       arranged in one or more columns.  There exist several different types
86       of entries, each with different properties.  Entries of different types
87       may be combined in a single menu.  Menu entries are not the same as
88       entry widgets.  In fact, menu entries are not even distinct widgets;
89       the entire menu is one widget.
90
91       Menu entries are displayed with up to three separate fields.  The main
92       field is a label in the form of a text string, a bitmap, or an image,
93       controlled by the -label, -bitmap, and -image options for the entry.
94       If the  -accelerator option is specified for an entry then a second
95       textual field is displayed to the right of the label.  The accelerator
96       typically describes a keystroke sequence that may be typed in the
97       application to cause the same result as invoking the menu entry.  The
98       third field is an indicator.  The indicator is present only for
99       checkbutton or radiobutton entries.  It indicates whether the entry is
100       selected or not, and is displayed to the left of the entry's string.
101
102       In normal use, an entry becomes active (displays itself differently)
103       whenever the mouse pointer is over the entry.  If a mouse button is
104       released over the entry then the entry is invoked.  The effect of
105       invocation is different for each type of entry; these effects are
106       described below in the sections on individual entries.
107
108       Entries may be disabled, which causes their labels and accelerators to
109       be displayed with dimmer colors.  The default menu bindings will not
110       allow a disabled entry to be activated or invoked.  Disabled entries
111       may be re-enabled, at which point it becomes possible to activate and
112       invoke them again.
113
114       Whenever a menu's active entry is changed, a <<MenuSelect>> virtual
115       event is sent to the menu. The active item can then be queried from the
116       menu, and an action can be taken, such as setting context-sensitive
117       help text for the entry.
118
119   COMMAND ENTRIES
120       The most common kind of menu entry is a command entry, which behaves
121       much like a button widget.  When a command entry is invoked, a callback
122       is executed.  The callback is specified with the -command option.
123
124   SEPARATOR ENTRIES
125       A separator is an entry that is displayed as a horizontal dividing
126       line.  A separator may not be activated or invoked, and it has no
127       behavior other than its display appearance.
128
129   CHECKBUTTON ENTRIES
130       A checkbutton menu entry behaves much like a checkbutton widget.  When
131       it is invoked it toggles back and forth between the selected and
132       deselected states.  When the entry is selected, a particular value is
133       stored in a particular global variable (as determined by the -onvalue
134       and -variable options for the entry);  when the entry is deselected
135       another value (determined by the -offvalue option) is stored in the
136       global variable.  An indicator box is displayed to the left of the
137       label in a checkbutton entry.  If the entry is selected then the
138       indicator's center is displayed in the color given by the -selectcolor
139       option for the entry; otherwise the indicator's center is displayed in
140       the background color for the menu.  If a -command option is specified
141       for a checkbutton entry, then its value is evaluated each time the
142       entry is invoked;  this happens after toggling the entry's selected
143       state.
144
145   RADIOBUTTON ENTRIES
146       A radiobutton menu entry behaves much like a radiobutton widget.
147       Radiobutton entries are organized in groups of which only one entry may
148       be selected at a time.  Whenever a particular entry becomes selected it
149       stores a particular value into a particular global variable (as
150       determined by the -value and -variable options for the entry).  This
151       action causes any previously-selected entry in the same group to
152       deselect itself.  Once an entry has become selected, any change to the
153       entry's associated variable will cause the entry to deselect itself.
154       Grouping of radiobutton entries is determined by their associated
155       variables:  if two entries have the same associated variable then they
156       are in the same group.  An indicator diamond is displayed to the left
157       of the label in each radiobutton entry.  If the entry is selected then
158       the indicator's center is displayed in the color given by the
159       -selectcolor option for the entry; otherwise the indicator's center is
160       displayed in the background color for the menu.  If a -command option
161       is specified for a radiobutton entry, then its value is evaluated each
162       time the entry is invoked;  this happens after selecting the entry.
163
164   CASCADE ENTRIES
165       A cascade entry is one with an associated menu (determined by the -menu
166       option).  Cascade entries allow the construction of cascading menus.
167       The postcascade method can be used to post and unpost the associated
168       menu just next to of the cascade entry.  The associated menu must be a
169       child of the menu containing the cascade entry (this is needed in order
170       for menu traversal to work correctly).
171
172       A cascade entry posts its associated menu by invoking
173
174           $menu->post(x,y)
175
176       where menu is the path name of the associated menu, and x and y are the
177       root-window coordinates of the upper-right corner of the cascade entry.
178       On Unix, the lower-level menu is unposted by executing
179
180           $menu->unpost
181
182       where menu is the name of the associated menu.  On other platforms, the
183       platform's native code takes care of unposting the menu.
184
185       If a -command option is specified for a cascade entry then it is
186       evaluated whenever the entry is invoked. This is not supported on
187       Windows.
188
189   TEAR-OFF ENTRIES
190       A tear-off entry appears at the top of the menu if enabled with the
191       tearOff option.  It is not like other menu entries in that it cannot be
192       created with the add method and cannot be deleted with the delete
193       method.  When a tear-off entry is created it appears as a dashed line
194       at the top of the menu.  Under the default bindings, invoking the tear-
195       off entry causes a torn-off copy to be made of the menu and all of its
196       submenus.
197
198   MENUBARS
199       Any menu can be set as a menubar for a toplevel window (see the
200       Toplevel constructor for syntax). On the Macintosh, whenever the
201       toplevel is in front, this menu's cascade items will appear in the
202       menubar across the top of the main monitor. On Windows and Unix, this
203       menu's items will be displayed in a menubar accross the top of the
204       window. These menus will behave according to the interface guidelines
205       of their platforms. For every menu set as a menubar, a clone menu is
206       made. See "CLONES" for more information.
207
208       As noted, menubars may behave differently on different platforms.   One
209       example  of this concerns the handling of checkbuttons and radiobuttons
210       within the menu.  While it is permitted to put these menu  elements  on
211       menubars,  they may not be drawn with indicators on some platforms, due
212       to system restrictions.
213
214   SPECIAL MENUS IN MENUBARS
215       Certain menus in a menubar will be treated specially.  On the
216       Macintosh, access to the special Apple and Help menus is provided. On
217       Windows, access to the Windows System menu in each window is provided.
218       On X Windows, a special right-justified help menu is provided. In all
219       cases, these menus must be created with the command name of the menubar
220       menu concatenated with the special name. So for a menubar named
221       .menubar, on the Macintosh, the special menus would be .menubar.apple
222       and .menubar.help; on Windows, the special menu would be
223       .menubar.system; on X Windows, the help menu would be .menubar.help.
224
225       When Tk sees an Apple menu on the Macintosh, that menu's contents make
226       up the first items of the Apple menu on the screen whenever the window
227       containing the menubar is in front. The menu is the first one that the
228       user sees and has a title which is an Apple logo.  After all of the Tk-
229       defined items, the menu will have a separator, followed by all of the
230       items in the user's Apple Menu Items folder.  Since the System uses a
231       different menu definition procedure for the Apple menu than Tk uses for
232       its menus, and the system APIs do not fully support everything Tk tries
233       to do, the menu item will only have its text displayed. No font
234       attributes, images, bitmaps, or colors will be displayed. In addition,
235       a menu with a tearoff item will have the tearoff item displayed as
236       "(TearOff)".
237
238       When Tk see a Help menu on the Macintosh, the menu's contents are
239       appended to the standard help menu on the right of the user's menubar
240       whenever the user's menubar is in front. The first items in the menu
241       are provided by Apple. Similar to the Apple Menu, cusomization in this
242       menu is limited to what the system provides.
243
244       When Tk sees a System menu on Windows, its items are appended to the
245       system menu that the menubar is attached to. This menu has an icon
246       representing a spacebar, and can be invoked with the mouse or by typing
247       Alt+Spacebar.  Due to limitations in the Windows API, any font changes,
248       colors, images, bitmaps, or tearoff images will not appear in the
249       system menu.
250
251       When Tk see a Help menu on X Windows, the menu is moved to be last in
252       the menubar and is right justified.
253
254   CLONES
255       When a menu is set as a menubar for a toplevel window, or when a menu
256       is torn off, a clone of the menu is made. This clone is a menu widget
257       in its own right, but it is a child of the original. Changes in the
258       configuration of the original are reflected in the clone. Additionally,
259       any cascades that are pointed to are also cloned so that menu traversal
260       will work right. Clones are destroyed when either the tearoff or
261       menubar goes away, or when the original menu is destroyed.
262
263   WIDGET METHODS
264       The Menu method creates a widget object.  This object supports the
265       configure and cget methods described in Tk::options which can be used
266       to enquire and modify the options described above.  The widget also
267       inherits all the methods provided by the generic Tk::Widget class, and
268       the Tk::Wm class.
269
270       Many of the methods for a menu take as one argument an indicator of
271       which entry of the menu to operate on.  These indicators are called
272       indexes and may be specified in any of the following forms:
273
274       number
275           Specifies the entry numerically, where 0 corresponds to the top-
276           most entry of the menu, 1 to the entry below it, and so on.
277
278       active
279           Indicates the entry that is currently active.  If no entry is
280           active then this form is equivalent to none.  This form may not be
281           abbreviated.
282
283       end Indicates the bottommost entry in the menu.  If there are no
284           entries in the menu then this form is equivalent to none.  This
285           form may not be abbreviated.
286
287       last
288           Same as end.
289
290       none
291           Indicates ``no entry at all'';  this is used most commonly with the
292           activate option to deactivate all the entries in the menu.  In most
293           cases the specification of none causes nothing to happen in the
294           method.  This form may not be abbreviated.
295
296       @number
297           In this form, number is treated as a y-coordinate in the menu's
298           window;  the entry closest to that y-coordinate is used.  For
299           example, ``@0'' indicates the top-most entry in the window.
300
301       pattern
302           If the index doesn't satisfy one of the above forms then this form
303           is used.  Pattern is pattern-matched against the label of each
304           entry in the menu, in order from the top down, until a matching
305           entry is found.  (In perl/Tk the matching is under review, but
306           exact match should work.)
307
308       The following methods are possible for menu widgets:
309
310       $menu->activate(index)
311           Change the state of the entry indicated by index to active and
312           redisplay it using its active colors.  Any previously-active entry
313           is deactivated.  If index is specified as none, or if the specified
314           entry is disabled, then the menu ends up with no active entry.
315           Returns an empty string.
316
317       $menu->add(type, ?option, value, option, value, ...?)
318           Add a new entry to the bottom of the menu.  The new entry's type is
319           given by type and must be one of cascade, checkbutton, command,
320           radiobutton, or separator, or a unique abbreviation of one of the
321           above.  If additional arguments are present, they specify any of
322           the following options:
323
324           -activebackground => value
325                   Specifies a background color to use for displaying this
326                   entry when it is active.  If this option is specified as an
327                   empty string (the default), then the activeBackground
328                   option for the overall menu is used.  If the
329                   $Tk::strictMotif variable has been set to request strict
330                   Motif compliance, then this option is ignored and the
331                   -background option is used in its place.  This option is
332                   not available for separator or tear-off entries.
333
334           -activeforeground => value
335                   Specifies a foreground color to use for displaying this
336                   entry when it is active.  If this option is specified as an
337                   empty string (the default), then the activeForeground
338                   option for the overall menu is used.  This option is not
339                   available for separator or tear-off entries.
340
341           -accelerator => value
342                   Specifies a string to display at the right side of the menu
343                   entry.  Normally describes an accelerator keystroke
344                   sequence that may be typed to invoke the same function as
345                   the menu entry.  This option is not available for separator
346                   or tear-off entries.
347
348           -background => value
349                   Specifies a background color to use for displaying this
350                   entry when it is in the normal state (neither active nor
351                   disabled).  If this option is specified as an empty string
352                   (the default), then the background option for the overall
353                   menu is used.  This option is not available for separator
354                   or tear-off entries.
355
356           -bitmap => value
357                   Specifies a bitmap to display in the menu instead of a
358                   textual label, in any of the forms accepted by
359                   Tk_GetBitmap.  This option overrides the -label option but
360                   may be reset to an empty string to enable a textual label
361                   to be displayed.  If a -image option has been specified, it
362                   overrides -bitmap.  This option is not available for
363                   separator or tear-off entries.
364
365           -columnbreak => value
366                   When this option is zero, the appears below the previous
367                   entry. When this option is one, the menu appears at the top
368                   of a new column in the menu.
369
370           -compound => value
371                   Specifies whether the button should display both an image
372                   and text, and if so, where the image should be placed
373                   relative to the text.  Valid values for this option are
374                   bottom, center, left, none, right and top.  The default
375                   value is none, meaning that the button will display either
376                   an image or text, depending on the values of the -image and
377                   -bitmap options.
378
379           -command => value
380                   For command, checkbutton, and radiobutton entries,
381                   specifies a callback to execute when the menu entry is
382                   invoked.  For cascade entries, specifies a callback to
383                   execute when the entry is activated (i.e. just before its
384                   submenu is posted).  Not available for separator or tear-
385                   off entries.
386
387           -font => value
388                   Specifies the font to use when drawing the label or
389                   accelerator string in this entry.  If this option is
390                   specified as an empty string (the default) then the font
391                   option for the overall menu is used.  This option is not
392                   available for separator or tear-off entries.
393
394           -foreground => value
395                   Specifies a foreground color to use for displaying this
396                   entry when it is in the normal state (neither active nor
397                   disabled).  If this option is specified as an empty string
398                   (the default), then the foreground option for the overall
399                   menu is used.  This option is not available for separator
400                   or tear-off entries.
401
402           -hidemargin => value
403                   Specifies whether the standard margins should be drawn for
404                   this menu entry. This is useful when creating palette with
405                   images in them, i.e., color palettes, pattern palettes,
406                   etc. 1 indicates that the margin for the entry is hidden; 0
407                   means that the margin is used.
408
409           -image => value
410                   Specifies an image to display in the menu instead of a text
411                   string or bitmap The image must have been created by some
412                   previous invocation of image create.  This option overrides
413                   the -label and -bitmap options but may be reset to an empty
414                   string to enable a textual or bitmap label to be displayed.
415                   This option is not available for separator or tear-off
416                   entries.
417
418           -indicatoron => value
419                   Available only for checkbutton and radiobutton entries.
420                   Value is a boolean that determines whether or not the
421                   indicator should be displayed.
422
423           -label => value
424                   Specifies a string to display as an identifying label in
425                   the menu entry.  Not available for separator or tear-off
426                   entries.
427
428           -menu => value
429                   Available only for cascade entries.  Specifies the path
430                   name of the submenu associated with this entry.  The
431                   submenu must be a child of the menu.
432
433           -offvalue => value
434                   Available only for checkbutton entries.  Specifies the
435                   value to store in the entry's associated variable when the
436                   entry is deselected.
437
438           -onvalue => value
439                   Available only for checkbutton entries.  Specifies the
440                   value to store in the entry's associated variable when the
441                   entry is selected.
442
443           -selectcolor => value
444                   Available only for checkbutton and radiobutton entries.
445                   Specifies the color to display in the indicator when the
446                   entry is selected.  If the value is an empty string (the
447                   default) then the selectColor option for the menu
448                   determines the indicator color.
449
450           -selectimage => value
451                   Available only for checkbutton and radiobutton entries.
452                   Specifies an image to display in the entry (in place of the
453                   -image option) when it is selected.  Value is the name of
454                   an image, which must have been created by some previous
455                   invocation of image create.  This option is ignored unless
456                   the -image option has been specified.
457
458           -state => value
459                   Specifies one of three states for the entry:  normal,
460                   active, or disabled.  In normal state the entry is
461                   displayed using the foreground option for the menu and the
462                   background option from the entry or the menu.  The active
463                   state is typically used when the pointer is over the entry.
464                   In active state the entry is displayed using the
465                   activeForeground option for the menu along with the
466                   activebackground option from the entry.  Disabled state
467                   means that the entry should be insensitive:  the default
468                   bindings will refuse to activate or invoke the entry.  In
469                   this state the entry is displayed according to the
470                   disabledForeground option for the menu and the background
471                   option from the entry.  This option is not available for
472                   separator entries.
473
474           -underline => value
475                   Specifies the integer index of a character to underline in
476                   the entry.  This option is also queried by the default
477                   bindings and used to implement keyboard traversal.  0
478                   corresponds to the first character of the text displayed in
479                   the entry, 1 to the next character, and so on.  If a bitmap
480                   or image is displayed in the entry then this option is
481                   ignored.  This option is not available for separator or
482                   tear-off entries.
483
484           -value => value
485                   Available only for radiobutton entries.  Specifies the
486                   value to store in the entry's associated variable when the
487                   entry is selected.  If an empty string is specified, then
488                   the -label option for the entry as the value to store in
489                   the variable.
490
491           -variable => value
492                   Available only for checkbutton and radiobutton entries.
493                   Specifies the name of a global value to set when the entry
494                   is selected.  For checkbutton entries the variable is also
495                   set when the entry is deselected.  For radiobutton entries,
496                   changing the variable causes the currently-selected entry
497                   to deselect itself.
498
499           The add method returns an empty string.
500
501       $menu->clone($parent ?, cloneType?)
502           Makes a clone of the current menu as a child of $parent. This clone
503           is a menu in its own right, but any changes to the clone are
504           propogated to the original menu and vice versa. cloneType can be
505           normal, menubar, or tearoff. Should not normally be called outside
506           of the Tk library. See "CLONES" for more information.
507
508       $menu->delete(index1?, index2?)
509           Delete all of the menu entries between index1 and index2 inclusive.
510           If index2 is omitted then it defaults to index1.  Attempts to
511           delete a tear-off menu entry are ignored (instead, you should
512           change the tearOff option to remove the tear-off entry).
513
514       $menu->entrycget(index, option)
515           Returns the current value of a configuration option for the entry
516           given by index.  Option may have any of the values accepted by the
517           add method.
518
519       $menu->entryconfigure(index ?,options?)
520           This method is similar to the configure method, except that it
521           applies to the options for an individual entry, whereas configure
522           applies to the options for the menu as a whole.  Options may have
523           any of the values accepted by the add method.  If options are
524           specified, options are modified as indicated in the method call and
525           the method returns an empty string.  If no options are specified,
526           returns a list describing the current options for entry index (see
527           Tk::options for information on the format of this list).
528
529       $menu->index(index)
530           Returns the numerical index corresponding to index, or none if
531           index was specified as none.
532
533       $menu->insert(index, type?, -option=>value, ...?)
534           Same as the add method except that it inserts the new entry just
535           before the entry given by index, instead of appending to the end of
536           the menu.  The type, -option, and value arguments have the same
537           interpretation as for the add widget method.  It is not possible to
538           insert new menu entries before the tear-off entry, if the menu has
539           one.
540
541       $menu->invoke(index)
542           Invoke the action of the menu entry.  See the sections on the
543           individual entries above for details on what happens.  If the menu
544           entry is disabled then nothing happens.  If the entry has a
545           callback associated with it then the result of that callback is
546           returned as the result of the invoke widget method.  Otherwise the
547           result is an empty string.  Note:  invoking a menu entry does not
548           automatically unpost the menu;  the default bindings normally take
549           care of this before invoking the invoke method.
550
551       $menu->post(x, y)
552           Arrange for the menu to be displayed on the screen at the root-
553           window coordinates given by x and y.  These coordinates are
554           adjusted if necessary to guarantee that the entire menu is visible
555           on the screen.  This method normally returns an empty string.  If
556           the postCommand option has been specified, then its value is
557           executed before posting the menu and the result of that callback is
558           returned as the result of the post widget method.  If an error
559           returns while executing the method, then the error is returned
560           without posting the menu.
561
562       $menu->postcascade(index)
563           Posts the submenu associated with the cascade entry given by index,
564           and unposts any previously posted submenu.  If index doesn't
565           correspond to a cascade entry, or if $menu isn't posted, the method
566           has no effect except to unpost any currently posted submenu.
567
568       $menu->type(index)
569           Returns the type of the menu entry given by index.  This is the
570           type argument passed to the add widget method when the entry was
571           created, such as command or separator, or tearoff for a tear-off
572           entry.
573
574       $menu->unpost
575           Unmap the window so that it is no longer displayed.  If a lower-
576           level cascaded menu is posted, unpost that menu.  Returns an empty
577           string. This method does not work on Windows and the Macintosh, as
578           those platforms have their own way of unposting menus.
579
580       $menu->yposition(index)
581           Returns a decimal string giving the y-coordinate within the menu
582           window of the topmost pixel in the entry specified by index.
583
585       The default bindings support four different ways of using menus:
586
587       Pulldown Menus in Menubar
588           This is the most command case. You create a menu widget that will
589           become the menu bar. You then add cascade entries to this menu,
590           specifying the pull down menus you wish to use in your menu bar.
591           You then create all of the pulldowns. Once you have done this,
592           specify the menu using the -menu option of the toplevel's method.
593           See the toplevel manual entry for details.
594
595       Pulldown Menus in Menu Buttons
596           This is the compatable way to do menu bars.  You create one
597           menubutton widget for each top-level menu, and typically you
598           arrange a series of menubuttons in a row in a menubar window.  You
599           also create the top-level menus and any cascaded submenus, and tie
600           them together with -menu options in menubuttons and cascade menu
601           entries.  The top-level menu must be a child of the menubutton, and
602           each submenu must be a child of the menu that refers to it.  Once
603           you have done this, the default bindings will allow users to
604           traverse and invoke the tree of menus via its menubutton;  see the
605           menubutton documentation for details.
606
607       Popup Menus
608           Popup menus typically post in response to a mouse button press or
609           keystroke.  You create the popup menus and any cascaded submenus,
610           then you call the Post method at the appropriate time to post the
611           top-level menu.
612
613           $menu->Post($x,$y?,$entry?)
614
615           $x and $y are the root window coordinates at which the $menu will
616           be displayed. If $entry is specified then that entry is centred on
617           that point, otherwise the top-left corner of the $menu is placed at
618           that point.
619
620           Menu also inherits methods from Tk::Wm and so the method Popup can
621           be used to position menu relative to other windows, the mouse
622           cursor or the screen.
623
624       Option Menus
625           An option menu consists of a menubutton with an associated menu
626           that allows you to select one of several values.  The current value
627           is displayed in the menubutton and is also stored in a global
628           variable.  Use the Tk::Optionmenu class to create option
629           menubuttons and their menus.
630
631       Torn-off Menus
632           You create a torn-off menu by invoking the tear-off entry at the
633           top of an existing menu.  The default bindings will create a new
634           menu that is a copy of the original menu and leave it permanently
635           posted as a top-level window.  The torn-off menu behaves just the
636           same as the original menu.
637

DEFAULT BINDINGS

639       Tk automatically creates class bindings for menus that give them the
640       following default behavior:
641
642       [1] When the mouse enters a menu, the entry underneath the mouse cursor
643           activates;  as the mouse moves around the menu, the active entry
644           changes to track the mouse.
645
646       [2] When the mouse leaves a menu all of the entries in the menu
647           deactivate, except in the special case where the mouse moves from a
648           menu to a cascaded submenu.
649
650       [3] When a button is released over a menu, the active entry (if any) is
651           invoked.  The menu also unposts unless it is a torn-off menu.
652
653       [4] The Space and Return keys invoke the active entry and unpost the
654           menu.
655
656       [5] If any of the entries in a menu have letters underlined with with
657           -underline option, then pressing one of the underlined letters (or
658           its upper-case or lower-case equivalent) invokes that entry and
659           unposts the menu.
660
661       [6] The Escape key aborts a menu selection in progress without invoking
662           any entry.  It also unposts the menu unless it is a torn-off menu.
663
664       [7] The Up and Down keys activate the next higher or lower entry in the
665           menu.  When one end of the menu is reached, the active entry wraps
666           around to the other end.
667
668       [8] The Left key moves to the next menu to the left.  If the current
669           menu is a cascaded submenu, then the submenu is unposted and the
670           current menu entry becomes the cascade entry in the parent.  If the
671           current menu is a top-level menu posted from a menubutton, then the
672           current menubutton is unposted and the next menubutton to the left
673           is posted.  Otherwise the key has no effect.  The left-right order
674           of menubuttons is determined by their stacking order:  Tk assumes
675           that the lowest menubutton (which by default is the first one
676           created) is on the left.
677
678       [9] The Right key moves to the next menu to the right.  If the current
679           entry is a cascade entry, then the submenu is posted and the
680           current menu entry becomes the first entry in the submenu.
681           Otherwise, if the current menu was posted from a menubutton, then
682           the current menubutton is unposted and the next menubutton to the
683           right is posted.
684
685           Disabled menu entries are non-responsive:  they don't activate and
686           they ignore mouse button presses and releases.
687
688           The behavior of menus can be changed by defining new bindings for
689           individual widgets or by redefining the class bindings.
690

BUGS

692       At present it isn't possible to use the option database to specify
693       values for the options to individual entries.
694

SEE ALSO

696       Tk::callbacks
697

KEYWORDS

699       menu, widget
700
701
702
703perl v5.32.0                      2020-07-28                           Menu(3)
Impressum