1menu(n)                      Tk Built-In Commands                      menu(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       menu, tk_menuSetFocus - Create and manipulate menu widgets
9

SYNOPSIS

11       menu pathName ?options?
12       tk_menuSetFocus pathName
13

STANDARD OPTIONS

15       -activebackground     -borderwidth         -foreground
16       -activeborderwidth    -cursor              -relief
17       -activeforeground     -disabledforeground  -takefocus
18       -background           -font
19
20
21       See the options manual entry for details on the standard options.
22

WIDGET-SPECIFIC OPTIONS

24       [-postcommand postCommand] If this option is specified then it provides │
25       a Tcl command to execute each time the menu is posted.  The command  is │
26       invoked  by  the post widget command before posting the menu. Note that │
27       in Tk 8.0 on Macintosh and Windows, all post-commands in  a  system  of │
28       menus  are  executed before any of those menus are posted.  This is due │
29       to  the  limitations  in  the  individual  platforms'  menu   managers.
30       [-selectcolor selectColor]  For  menu entries that are check buttons or
31       radio buttons, this option specifies the color to display in the  indi‐
32       cator   when   the   check   button   or   radio  button  is  selected.
33       [-tearoff tearOff] This option must have a proper boolean value,  which
34       specifies  whether  or  not the menu should include a tear-off entry at
35       the top.  If so, it will exist as entry 0 of the  menu  and  the  other
36       entries  will  number starting at 1.  The default menu bindings arrange
37       for the menu to be  torn  off  when  the  tear-off  entry  is  invoked.
38       [-tearoffcommand tearOffCommand]  If this option has a non-empty value,
39       then it specifies a Tcl command to invoke whenever  the  menu  is  torn
40       off.  The actual command will consist of the value of this option, fol‐
41       lowed by a space, followed by the name of the menu window, followed  by
42       a  space, followed by the name of the name of the torn off menu window.
43       For example, if the option's is ``a b'' and menu .x.y is  torn  off  to
44       create   a   new   menu  .x.tearoff1,  then  the  command  ``a  b  .x.y
45       .x.tearoff1'' will be invoked.  [-title title] The string will be  used │
46       to title the window created when this menu is torn off. If the title is │
47       NULL, then the window will have the title of the menubutton or the text │
48       of  the  cascade  item  from which this menu was invoked.  [-type type] │
49       This option can be one of menubar, tearoff, or normal, and is set  when │
50       the  menu  is  created.  While the string returned by the configuration │
51       database will change if this option is changed, this  does  not  affect │
52       the  menu  widget's behavior. This is used by the cloning mechanism and │
53       is not normally set outside of the Tk library.
54_________________________________________________________________
55
56

INTRODUCTION

58       The menu command creates a new top-level window (given by the  pathName
59       argument)  and  makes  it  into  a  menu  widget.   Additional options,
60       described above, may be specified on the command line or in the  option
61       database  to configure aspects of the menu such as its colors and font.
62       The menu command returns its pathName argument.  At the time this  com‐
63       mand  is  invoked,  there  must  not exist a window named pathName, but
64       pathName's parent must exist.
65
66       A menu is a widget that  displays  a  collection  of  one-line  entries │
67       arranged  in  one or more columns.  There exist several different types │
68       of entries, each with different properties.  Entries of different types │
69       may  be  combined  in  a single menu.  Menu entries are not the same as │
70       entry widgets.  In fact, menu entries are not  even  distinct  widgets; │
71       the entire menu is one widget.
72
73       Menu  entries are displayed with up to three separate fields.  The main
74       field is a label in the form of a text string, a bitmap, or  an  image,
75       controlled  by  the  -label, -bitmap, and -image options for the entry.
76       If the  -accelerator option is specified for an  entry  then  a  second
77       textual  field is displayed to the right of the label.  The accelerator
78       typically describes a keystroke sequence  that  may  be  typed  in  the
79       application  to  cause the same result as invoking the menu entry.  The
80       third field is an indicator.  The indicator is present only for  check‐
81       button  or  radiobutton  entries.   It  indicates  whether the entry is
82       selected or not, and is displayed to the left of the entry's string.
83
84       In normal use, an entry becomes active  (displays  itself  differently)
85       whenever  the  mouse  pointer  is over the entry.  If a mouse button is
86       released over the entry then the entry is invoked.  The effect of invo‐
87       cation is different for each type of entry; these effects are described
88       below in the sections on individual entries.
89
90       Entries may be disabled, which causes their labels and accelerators  to
91       be  displayed  with  dimmer colors.  The default menu bindings will not
92       allow a disabled entry to be activated or  invoked.   Disabled  entries
93       may  be  re-enabled, at which point it becomes possible to activate and
94       invoke them again.                                                      │
95
96       Whenever a menu's active entry is  changed,  a  <<MenuSelect>>  virtual │
97       event is send to the menu. The active item can then be queried from the │
98       menu, and an action can be taken,  such  as  setting  context-sensitive │
99       help text for the entry.
100
101

COMMAND ENTRIES

103       The  most  common  kind of menu entry is a command entry, which behaves
104       much like a button widget.  When a command entry is invoked, a Tcl com‐
105       mand  is  executed.   The  Tcl  command  is specified with the -command
106       option.
107
108

SEPARATOR ENTRIES

110       A separator is an entry that is  displayed  as  a  horizontal  dividing
111       line.   A  separator  may  not  be  activated or invoked, and it has no
112       behavior other than its display appearance.
113
114

CHECKBUTTON ENTRIES

116       A checkbutton menu entry behaves much like a checkbutton widget.   When
117       it  is invoked it toggles back and forth between the selected and dese‐
118       lected states.  When the entry  is  selected,  a  particular  value  is
119       stored  in  a particular global variable (as determined by the -onvalue
120       and -variable options for the entry);  when  the  entry  is  deselected
121       another  value  (determined  by  the -offvalue option) is stored in the
122       global variable.  An indicator box is displayed  to  the  left  of  the
123       label  in a checkbutton entry.  If the entry is selected then the indi‐
124       cator's center is displayed in the  color  given  by  the  -selectcolor
125       option  for the entry; otherwise the indicator's center is displayed in
126       the background color for the menu.  If a -command option  is  specified
127       for  a  checkbutton entry, then its value is evaluated as a Tcl command
128       each time the entry  is  invoked;   this  happens  after  toggling  the
129       entry's selected state.
130
131

RADIOBUTTON ENTRIES

133       A  radiobutton  menu  entry  behaves  much  like  a radiobutton widget.
134       Radiobutton entries are organized in groups of which only one entry may
135       be selected at a time.  Whenever a particular entry becomes selected it
136       stores a particular value into a particular global variable (as  deter‐
137       mined  by the -value and -variable options for the entry).  This action
138       causes any previously-selected entry in  the  same  group  to  deselect
139       itself.   Once  an entry has become selected, any change to the entry's
140       associated variable will cause the entry to deselect itself.   Grouping
141       of radiobutton entries is determined by their associated variables:  if
142       two entries have the same associated variable then they are in the same
143       group.   An  indicator diamond is displayed to the left of the label in
144       each radiobutton entry.  If the entry is selected then the  indicator's
145       center  is  displayed in the color given by the -selectcolor option for
146       the entry; otherwise the indicator's center is displayed in  the  back‐
147       ground  color  for  the  menu.  If a -command option is specified for a
148       radiobutton entry, then its value is evaluated as a  Tcl  command  each
149       time the entry is invoked;  this happens after selecting the entry.
150
151

CASCADE ENTRIES

153       A cascade entry is one with an associated menu (determined by the -menu
154       option).  Cascade entries allow the construction  of  cascading  menus.
155       The postcascade widget command can be used to post and unpost the asso‐
156       ciated menu just next to of the cascade  entry.   The  associated  menu
157       must  be  a  child  of  the  menu containing the cascade entry (this is
158       needed in order for menu traversal to work correctly).
159
160       A cascade entry posts its associated menu by invoking a Tcl command  of
161       the form
162              menu post x y
163       where menu is the path name of the associated menu, and x and y are the
164       root-window coordinates of the upper-right corner of the cascade entry. │
165       On  Unix,  the  lower-level menu is unposted by executing a Tcl command │
166       with the form                                                           │
167              menu unpost                                                      
168       where menu is the name of the associated menu.  On other platforms, the │
169       platform's native code takes care of unposting the menu.
170
171       If a -command option is specified for a cascade entry then it is evalu‐ │
172       ated as a Tcl command whenever the entry is invoked. This is  not  sup‐ │
173       ported on Windows.
174
175

TEAR-OFF ENTRIES

177       A  tear-off  entry  appears  at the top of the menu if enabled with the
178       tearOff option.  It is not like other menu entries in that it cannot be
179       created  with  the  add  widget  command and cannot be deleted with the
180       delete widget command.  When a tear-off entry is created it appears  as
181       a  dashed  line  at  the  top of the menu.  Under the default bindings,
182       invoking the tear-off entry causes a torn-off copy to be  made  of  the
183       menu and all of its submenus.
184
185
187       Any  menu  can  be set as a menubar for a toplevel window (see toplevel 
188       command for syntax). On the Macintosh,  whenever  the  toplevel  is  in │
189       front,  this menu's cascade items will appear in the menubar across the │
190       top of the main monitor. On Windows and Unix, this menu's items will be │
191       displayed  in  a menubar across the top of the window. These menus will │
192       behave according to the interface guidelines of  their  platforms.  For │
193       every  menu set as a menubar, a clone menu is made. See the CLONES sec‐ │
194       tion for more information.                                              │
195
196       As noted, menubars may behave differently on different platforms.   One │
197       example  of this concerns the handling of checkbuttons and radiobuttons │
198       within the menu.  While it is permitted to put these menu  elements  on │
199       menubars,  they may not be drawn with indicators on some platforms, due │
200       to system restrictions.
201
202

SPECIAL MENUS IN MENUBARS │

204       Certain menus in a menubar will be treated specially.   On  the  Macin‐ │
205       tosh,  access  to the special Apple and Help menus is provided. On Win‐ │
206       dows, access to the Windows System menu in each window is provided.  On │
207       X  Windows,  a  special  right-justified  help menu is provided. In all │
208       cases, these menus must be created with the command name of the menubar │
209       menu  concatenated  with  the  special  name.  So  for  a menubar named │
210       .menubar, on the Macintosh, the special menus would  be  .menubar.apple │
211       and  .menubar.help; on Windows, the special menu would be .menubar.sys‐ │
212       tem; on X Windows, the help menu would be .menubar.help.                │
213
214       When Tk sees an Apple menu on the Macintosh, that menu's contents  make │
215       up  the first items of the Apple menu on the screen whenever the window │
216       containing the menubar is in front. The menu is the first one that  the │
217       user sees and has a title which is an Apple logo.  After all of the Tk- │
218       defined items, the menu will have a separator, followed by all  of  the │
219       items  in  the user's Apple Menu Items folder.  Since the System uses a │
220       different menu definition procedure for the Apple menu than Tk uses for │
221       its menus, and the system APIs do not fully support everything Tk tries │
222       to do, the menu item  will  only  have  its  text  displayed.  No  font │
223       attributes,  images, bitmaps, or colors will be displayed. In addition, │
224       a menu with a tearoff item will have  the  tearoff  item  displayed  as │
225       "(TearOff)".                                                            │
226
227       When  Tk  see  a  Help  menu  on the Macintosh, the menu's contents are │
228       appended to the standard help menu on the right of the  user's  menubar │
229       whenever  the  user's  menubar is in front. The first items in the menu │
230       are provided by Apple. Similar to the Apple Menu, customization in this │
231       menu is limited to what the system provides.                            │
232
233       When  Tk  sees  a System menu on Windows, its items are appended to the │
234       system menu that the menubar is attached to. This menu has an icon rep‐ │
235       resenting  a  spacebar,  and can be invoked with the mouse or by typing │
236       Alt+Spacebar.  Due to limitations in the Windows API, any font changes, │
237       colors,  images, bitmaps, or tearoff images will not appear in the sys‐ │
238       tem menu.                                                               │
239
240       When Tk see a Help menu on X Windows, the menu is moved to be  last  in │
241       the menubar and is right justified.
242
243

CLONES │

245       When  a  menu is set as a menubar for a toplevel window, or when a menu │
246       is torn off, a clone of the menu is made. This clone is a  menu  widget │
247       in  its  own  right,  but it is a child of the original. Changes in the │
248       configuration of the original are reflected in the clone. Additionally, │
249       any cascades that are pointed to are also cloned so that menu traversal │
250       will work right. Clones  are  destroyed  when  either  the  tearoff  or │
251       menubar goes away, or when the original menu is destroyed.
252
253

WIDGET COMMAND

255       The  menu  command  creates  a  new Tcl command whose name is pathName.
256       This command may be used to invoke various operations  on  the  widget.
257       It has the following general form:
258              pathName option ?arg arg ...?
259       Option and the args determine the exact behavior of the command.
260
261       Many  of the widget commands for a menu take as one argument an indica‐
262       tor of which entry of the menu to operate  on.   These  indicators  are
263       called indexes and may be specified in any of the following forms:
264
265       number      Specifies the entry numerically, where 0 corresponds to the
266                   top-most entry of the menu, 1 to the entry below it, and so
267                   on.
268
269       active      Indicates  the entry that is currently active.  If no entry
270                   is active then this form is equivalent to none.  This  form
271                   may not be abbreviated.
272
273       end         Indicates  the  bottommost entry in the menu.  If there are
274                   no entries in the menu then  this  form  is  equivalent  to
275                   none.  This form may not be abbreviated.
276
277       last        Same as end.
278
279       none        Indicates  ``no entry at all'';  this is used most commonly
280                   with the activate option to deactivate all the  entries  in
281                   the  menu.   In most cases the specification of none causes
282                   nothing to happen in the widget command.  This form may not
283                   be abbreviated.
284
285       @number     In  this  form,  number is treated as a y-coordinate in the
286                   menu's window;  the entry closest to that  y-coordinate  is
287                   used.   For example, ``@0'' indicates the top-most entry in
288                   the window.
289
290       pattern     If the index doesn't satisfy one of the  above  forms  then
291                   this  form is used.  Pattern is pattern-matched against the
292                   label of each entry in the menu,  in  order  from  the  top
293                   down,  until  a  matching  entry  is  found.   The rules of
294                   Tcl_StringMatch are used.
295
296       The following widget commands are possible for menu widgets:
297
298       pathName activate index
299              Change the state of the entry indicated by index to  active  and
300              redisplay  it  using  its  active colors.  Any previously-active
301              entry is deactivated.  If index is specified as none, or if  the
302              specified  entry  is  disabled,  then  the  menu ends up with no
303              active entry.  Returns an empty string.
304
305       pathName add type ?option value option value ...?
306              Add a new entry to the bottom of the menu.  The new entry's type
307              is  given  by type and must be one of cascade, checkbutton, com‐
308              mand, radiobutton, or separator, or a unique abbreviation of one
309              of the above.  If additional arguments are present, they specify
310              any of the following options:
311
312              -activebackground value
313                     Specifies a background color to use for  displaying  this
314                     entry  when it is active.  If this option is specified as
315                     an empty string (the default), then the  activeBackground
316                     option for the overall menu is used.  If the tk_strictMo‐
317                     tif variable has been set to request strict Motif compli‐
318                     ance,  then  this  option  is ignored and the -background
319                     option is used in its place.  This option is  not  avail‐
320                     able for separator or tear-off entries.
321
322              -activeforeground value
323                     Specifies  a  foreground color to use for displaying this
324                     entry when it is active.  If this option is specified  as
325                     an  empty string (the default), then the activeForeground
326                     option for the overall menu is used.  This option is  not
327                     available for separator or tear-off entries.
328
329              -accelerator value
330                     Specifies  a  string  to display at the right side of the
331                     menu entry.  Normally describes an accelerator  keystroke
332                     sequence that may be typed to invoke the same function as
333                     the menu entry.  This option is not available for separa‐
334                     tor or tear-off entries.
335
336              -background value
337                     Specifies  a  background color to use for displaying this
338                     entry when it is in the normal state (neither active  nor
339                     disabled).   If  this  option  is  specified  as an empty
340                     string (the default), then the background option for  the
341                     overall  menu  is used.  This option is not available for
342                     separator or tear-off entries.
343
344              -bitmap value
345                     Specifies a bitmap to display in the menu  instead  of  a
346                     textual  label,  in  any of the forms accepted by Tk_Get‐
347                     Bitmap.  This option overrides the -label option (as con‐
348                     trolled  by  the -compound option) but may be reset to an
349                     empty string to enable a textual label to  be  displayed.
350                     If a -image option has been specified, it overrides -bit‐
351                     map.  This option is not available for separator or tear-
352                     off entries.
353
354              -columnbreak value
355                     When  this  option  is  zero, the entry appears below the │
356                     previous entry.  When  this  option  is  one,  the  entry │
357                     appears at the top of a new column in the menu.
358
359              -command value
360                     Specifies a Tcl command to execute when the menu entry is
361                     invoked.   Not  available  for  separator   or   tear-off
362                     entries.                                                  │
363
364              -compound value                                                  │
365                     Specifies  whether  the menu entry should display both an │
366                     image and text, and if so,  where  the  image  should  be │
367                     placed  relative  to  the  text.   Valid  values for this │
368                     option are bottom, center, left,  none,  right  and  top. │
369                     The  default  value is none, meaning that the button will │
370                     display either an image or text, depending on the  values │
371                     of the -image and -bitmap options.
372
373              -font value
374                     Specifies  the  font  to  use  when  drawing the label or
375                     accelerator string in this  entry.   If  this  option  is
376                     specified  as an empty string (the default) then the font
377                     option for the overall menu is used.  This option is  not
378                     available for separator or tear-off entries.
379
380              -foreground value
381                     Specifies  a  foreground color to use for displaying this
382                     entry when it is in the normal state (neither active  nor
383                     disabled).   If  this  option  is  specified  as an empty
384                     string (the default), then the foreground option for  the
385                     overall  menu  is used.  This option is not available for
386                     separator or tear-off entries.                            │
387
388              -hidemargin value                                                │
389                     Specifies whether the standard margins  should  be  drawn │
390                     for this menu entry. This is useful when creating palette │
391                     with images in them, i.e., color palettes,  pattern  pal‐ │
392                     ettes,  etc. 1 indicates that the margin for the entry is │
393                     hidden; 0 means that the margin is used.
394
395              -image value
396                     Specifies an image to display in the menu  instead  of  a
397                     text  string or bitmap.  The image must have been created
398                     by some previous invocation of image create.  This option
399                     overrides  the  -label and -bitmap options (as controlled
400                     by the -compound option) but may be  reset  to  an  empty
401                     string  to  enable  a  textual or bitmap label to be dis‐
402                     played.  This option is not available  for  separator  or
403                     tear-off entries.
404
405              -indicatoron value
406                     Available  only  for checkbutton and radiobutton entries.
407                     Value is a boolean that determines  whether  or  not  the
408                     indicator should be displayed.
409
410              -label value
411                     Specifies  a string to display as an identifying label in
412                     the menu entry.  Not available for separator or  tear-off
413                     entries.
414
415              -menu value
416                     Available  only  for cascade entries.  Specifies the path
417                     name of the submenu associated with this entry.  The sub‐
418                     menu must be a child of the menu.
419
420              -offvalue value
421                     Available  only  for  checkbutton entries.  Specifies the
422                     value to store in the entry's  associated  variable  when
423                     the entry is deselected.
424
425              -onvalue value
426                     Available  only  for  checkbutton entries.  Specifies the
427                     value to store in the entry's  associated  variable  when
428                     the entry is selected.
429
430              -selectcolor value
431                     Available  only  for checkbutton and radiobutton entries.
432                     Specifies the color to display in the indicator when  the
433                     entry  is selected.  If the value is an empty string (the
434                     default) then the selectColor option for the menu  deter‐
435                     mines the indicator color.
436
437              -selectimage value
438                     Available  only  for checkbutton and radiobutton entries.
439                     Specifies an image to display in the entry (in  place  of
440                     the  -image  option)  when  it is selected.  Value is the
441                     name of an image, which must have been  created  by  some
442                     previous  invocation  of  image  create.   This option is
443                     ignored unless the -image option has been specified.
444
445              -state value
446                     Specifies one of three states  for  the  entry:   normal,
447                     active,  or  disabled.  In normal state the entry is dis‐
448                     played using the foreground option for the menu  and  the
449                     background option from the entry or the menu.  The active
450                     state is typically used when  the  pointer  is  over  the
451                     entry.   In active state the entry is displayed using the
452                     activeForeground option  for  the  menu  along  with  the
453                     activebackground  option  from the entry.  Disabled state
454                     means that the entry should be insensitive:  the  default
455                     bindings will refuse to activate or invoke the entry.  In
456                     this state the entry is displayed according to  the  dis‐
457                     abledForeground  option  for  the menu and the background
458                     option from the entry.  This option is not available  for
459                     separator entries.
460
461              -underline value
462                     Specifies  the  integer index of a character to underline
463                     in the entry.  This option is also queried by the default
464                     bindings  and  used  to  implement keyboard traversal.  0
465                     corresponds to the first character of the text  displayed
466                     in  the  entry, 1 to the next character, and so on.  If a
467                     bitmap or image is  displayed  in  the  entry  then  this
468                     option is ignored.  This option is not available for sep‐
469                     arator or tear-off entries.
470
471              -value value
472                     Available only for radiobutton  entries.   Specifies  the
473                     value  to  store  in the entry's associated variable when
474                     the entry is selected.  If an empty string is  specified,
475                     then  the  -label  option  for  the entry as the value to
476                     store in the variable.
477
478              -variable value
479                     Available only for checkbutton and  radiobutton  entries.
480                     Specifies  the  name  of  a  global value to set when the
481                     entry is selected.  For checkbutton entries the  variable
482                     is  also set when the entry is deselected.  For radiobut‐
483                     ton entries, changing the variable causes the  currently-
484                     selected entry to deselect itself.
485
486              The add widget command returns an empty string.
487
488       pathName cget option
489              Returns  the  current value of the configuration option given by
490              option.  Option may have any of the values accepted by the  menu
491              command.                                                         │
492
493       pathName clone newPathname ?cloneType?
494              Makes  a clone of the current menu named newPathName. This clone │
495              is a menu in its own right, but any changes  to  the  clone  are │
496              propogated to the original menu and vice versa. cloneType can be │
497              normal, menubar, or tearoff. Should not normally be called  out‐ │
498              side of the Tk library. See the CLONES section for more informa‐ │
499              tion.
500
501       pathName configure ?option? ?value option value ...?
502              Query or modify the configuration options of the widget.  If  no
503              option is specified, returns a list describing all of the avail‐
504              able options for pathName (see Tk_ConfigureInfo for  information
505              on  the  format  of  this list).  If option is specified with no
506              value, then the command returns a list describing the one  named
507              option (this list will be identical to the corresponding sublist
508              of the value returned if no option is  specified).   If  one  or
509              more option-value pairs are specified, then the command modifies
510              the given widget option(s) to have the given value(s);  in  this
511              case  the  command returns an empty string.  Option may have any
512              of the values accepted by the menu command.
513
514       pathName delete index1 ?index2?
515              Delete all of the menu entries between index1 and index2  inclu‐
516              sive.   If  index2  is  omitted  then  it  defaults  to  index1.
517              Attempts to delete a tear-off menu entry are  ignored  (instead,
518              you  should  change  the  tearOff  option to remove the tear-off
519              entry).
520
521       pathName entrycget index option
522              Returns the current value of  a  configuration  option  for  the
523              entry  given  by  index.   Option  may  have  any  of the values
524              accepted by the add widget command.
525
526       pathName entryconfigure index ?options?
527              This command is similar to the configure command, except that it
528              applies  to the options for an individual entry, whereas config‐
529              ure applies to the options for the menu as a whole.  Options may
530              have  any  of the values accepted by the add widget command.  If
531              options are specified, options are modified as indicated in  the
532              command  and the command returns an empty string.  If no options
533              are specified, returns a list describing the current options for
534              entry  index (see Tk_ConfigureInfo for information on the format
535              of this list).
536
537       pathName index index
538              Returns the numerical index corresponding to index, or  none  if
539              index was specified as none.
540
541       pathName insert index type ?option value option value ...?
542              Same  as  the  add widget command except that it inserts the new
543              entry just before the entry given by index, instead of appending
544              to  the  end of the menu.  The type, option, and value arguments
545              have the same interpretation as for the add widget command.   It
546              is  not  possible to insert new menu entries before the tear-off
547              entry, if the menu has one.
548
549       pathName invoke index
550              Invoke the action of the menu entry.  See the  sections  on  the
551              individual  entries  above  for details on what happens.  If the
552              menu entry is disabled then nothing happens.  If the entry has a
553              command  associated  with  it then the result of that command is
554              returned as the result of the invoke widget command.   Otherwise
555              the  result  is  an  empty string.  Note:  invoking a menu entry
556              does not automatically unpost the menu;   the  default  bindings
557              normally  take  care  of  this before invoking the invoke widget
558              command.
559
560       pathName post x y
561              Arrange for the menu to be displayed on the screen at the  root-
562              window  coordinates  given  by  x  and y.  These coordinates are
563              adjusted if necessary to guarantee that the entire menu is visi‐
564              ble  on  the  screen.   This  command  normally returns an empty
565              string.  If the postCommand option has been specified, then  its
566              value  is  executed  as a Tcl script before posting the menu and
567              the result of that script is returned as the result of the  post
568              widget  command.   If  an error returns while executing the com‐
569              mand, then the error is returned without posting the menu.
570
571       pathName postcascade index
572              Posts the submenu associated with the  cascade  entry  given  by
573              index,  and  unposts  any  previously  posted submenu.  If index
574              doesn't correspond to a cascade  entry,  or  if  pathName  isn't
575              posted, the command has no effect except to unpost any currently
576              posted submenu.
577
578       pathName type index
579              Returns the type of the menu entry given by index.  This is  the
580              type  argument  passed  to the add widget command when the entry
581              was created, such as command or  separator,  or  tearoff  for  a
582              tear-off entry.
583
584       pathName unpost
585              Unmap the window so that it is no longer displayed.  If a lower- │
586              level cascaded menu is posted, unpost  that  menu.   Returns  an │
587              empty  string.  This subcommand does not work on Windows and the │
588              Macintosh, as those platforms have their own  way  of  unposting │
589              menus.
590
591       pathName yposition index
592              Returns a decimal string giving the y-coordinate within the menu
593              window of the topmost pixel in the entry specified by index.
594
595
597       The default bindings support four different ways of using menus:        │
598
599       Pulldown Menus in Menubar                                               
600              This is the most command case. You create  a  menu  widget  that │
601              will  become  the menu bar. You then add cascade entries to this │
602              menu, specifying the pull down menus you wish  to  use  in  your │
603              menu  bar.  You  then create all of the pulldowns. Once you have │
604              done this, specify the  menu  using  the  -menu  option  of  the │
605              toplevel's  widget  command.  See  the toplevel manual entry for │
606              details.
607
608       Pulldown Menus in Menu Buttons
609              This is the compatable way to do  menu  bars.   You  create  one
610              menubutton  widget  for  each  top-level menu, and typically you
611              arrange a series of menubuttons in a row in  a  menubar  window.
612              You  also  create the top-level menus and any cascaded submenus,
613              and tie them together with -menu options in menubuttons and cas‐
614              cade  menu  entries.   The top-level menu must be a child of the
615              menubutton, and each submenu must be a child of  the  menu  that
616              refers  to  it.   Once  you have done this, the default bindings
617              will allow users to traverse and invoke the tree  of  menus  via
618              its menubutton;  see the menubutton manual entry for details.
619
620       Popup Menus
621              Popup  menus  typically post in response to a mouse button press
622              or keystroke.  You create the popup menus and any cascaded  sub‐
623              menus,  then  you call the tk_popup procedure at the appropriate
624              time to post the top-level menu.
625
626       Option Menus
627              An option menu consists of a menubutton with an associated  menu
628              that  allows  you  to select one of several values.  The current
629              value is displayed in the menubutton and is  also  stored  in  a
630              global  variable.   Use  the  tk_optionMenu  procedure to create
631              option menubuttons and their menus.
632
633       Torn-off Menus
634              You create a torn-off menu by invoking the tear-off entry at the
635              top of an existing menu.  The default bindings will create a new
636              menu that is a copy of the original menu  and  leave  it  perma‐
637              nently  posted as a top-level window.  The torn-off menu behaves
638              just the same as the original menu.
639
640

DEFAULT BINDINGS

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

BUGS

701       At present it isn't possible to use the option database to specify val‐
702       ues for the options to individual entries.
703
704

KEYWORDS

706       menu, widget
707
708
709
710Tk                                    4.1                              menu(n)
Impressum