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 -active‐
13       borderwidth  -borderwidth   -font     -takefocus -activefore‐
14       ground   -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 com‐
50           mand will consist of the value of this option, followed by a space,
51           followed by the name of the menu window, followed by a space, fol‐
52           lowed by the name of the name of the torn off menu window.  For
53           example, if the option's is ``a b'' and menu .x.y is torn off to
54           create a new menu .x.tearoff1, then the command ``a b .x.y
55           .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 configu‐
70           ration database will change if this option is changed, this does
71           not affect the menu widget's behavior. This is used by the cloning
72           mechanism and is not normally set outside of the Tk library.
73

DESCRIPTION

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

DEFAULT BINDINGS

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

BUGS

698       At present it isn't possible to use the option database to specify val‐
699       ues for the options to individual entries.
700

SEE ALSO

702       Tk::callbacks
703

KEYWORDS

705       menu, widget
706
707
708
709perl v5.8.8                       2008-02-05                           Menu(3)
Impressum