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       See the options manual entry for details on the standard options.
21

WIDGET-SPECIFIC OPTIONS

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

INTRODUCTION

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

TYPES OF ENTRIES

100   COMMAND ENTRIES
101       The  most  common  kind of menu entry is a command entry, which behaves
102       much like a button widget.  When a command entry is invoked, a Tcl com‐
103       mand  is  executed.   The  Tcl  command  is specified with the -command
104       option.
105
106   SEPARATOR ENTRIES
107       A separator is an entry that is  displayed  as  a  horizontal  dividing
108       line.   A  separator  may  not  be  activated or invoked, and it has no
109       behavior other than its display appearance.
110
111   CHECKBUTTON ENTRIES
112       A checkbutton menu entry behaves much like a checkbutton widget.   When
113       it  is invoked it toggles back and forth between the selected and dese‐
114       lected states.  When the entry  is  selected,  a  particular  value  is
115       stored  in  a particular global variable (as determined by the -onvalue
116       and -variable options for the entry);  when  the  entry  is  deselected
117       another  value  (determined  by  the -offvalue option) is stored in the
118       global variable.  An indicator box is displayed  to  the  left  of  the
119       label  in a checkbutton entry.  If the entry is selected then the indi‐
120       cator's center is displayed in the  color  given  by  the  -selectcolor
121       option  for the entry; otherwise the indicator's center is displayed in
122       the background color for the menu.  If a -command option  is  specified
123       for  a  checkbutton entry, then its value is evaluated as a Tcl command
124       each time the entry  is  invoked;   this  happens  after  toggling  the
125       entry's selected state.
126
127   RADIOBUTTON ENTRIES
128       A  radiobutton  menu  entry  behaves  much  like  a radiobutton widget.
129       Radiobutton entries are organized in groups of which only one entry may
130       be selected at a time.  Whenever a particular entry becomes selected it
131       stores a particular value into a particular global variable (as  deter‐
132       mined  by the -value and -variable options for the entry).  This action
133       causes any previously-selected entry in  the  same  group  to  deselect
134       itself.   Once  an entry has become selected, any change to the entry's
135       associated variable will cause the entry to deselect itself.   Grouping
136       of radiobutton entries is determined by their associated variables:  if
137       two entries have the same associated variable then they are in the same
138       group.   An  indicator diamond is displayed to the left of the label in
139       each radiobutton entry.  If the entry is selected then the  indicator's
140       center  is  displayed in the color given by the -selectcolor option for
141       the entry; otherwise the indicator's center is displayed in  the  back‐
142       ground  color  for  the  menu.  If a -command option is specified for a
143       radiobutton entry, then its value is evaluated as a  Tcl  command  each
144       time the entry is invoked;  this happens after selecting the entry.
145
146   CASCADE ENTRIES
147       A cascade entry is one with an associated menu (determined by the -menu
148       option).  Cascade entries allow the construction  of  cascading  menus.
149       The postcascade widget command can be used to post and unpost the asso‐
150       ciated menu just next to of the cascade  entry.   The  associated  menu
151       must  be  a  child  of  the  menu containing the cascade entry (this is
152       needed in order for menu traversal to work correctly).
153
154       A cascade entry posts its associated menu by invoking a Tcl command  of
155       the form
156              menu post x y
157       where menu is the path name of the associated menu, and x and y are the
158       root-window coordinates of the upper-right corner of the cascade entry.
159       On  Unix,  the  lower-level menu is unposted by executing a Tcl command
160       with the form
161              menu unpost
162       where menu is the name of the associated menu.  On other platforms, the
163       platform's native code takes care of unposting the menu.
164
165       If a -command option is specified for a cascade entry then it is evalu‐
166       ated as a Tcl command whenever the entry is invoked. This is  not  sup‐
167       ported on Windows.
168
169   TEAR-OFF ENTRIES
170       A  tear-off  entry  appears  at the top of the menu if enabled with the
171       tearOff option.  It is not like other menu entries in that it cannot be
172       created  with  the  add  widget  command and cannot be deleted with the
173       delete widget command.  When a tear-off entry is created it appears  as
174       a  dashed  line  at  the  top of the menu.  Under the default bindings,
175       invoking the tear-off entry causes a torn-off copy to be  made  of  the
176       menu and all of its submenus.
177
179       Any  menu  can  be set as a menubar for a toplevel window (see toplevel
180       command for syntax). On the Macintosh,  whenever  the  toplevel  is  in
181       front,  this menu's cascade items will appear in the menubar across the
182       top of the main monitor. On Windows and Unix, this menu's items will be
183       displayed  in  a menubar across the top of the window. These menus will
184       behave according to the interface guidelines of  their  platforms.  For
185       every  menu set as a menubar, a clone menu is made. See the CLONES sec‐
186       tion for more information.
187
188       As noted, menubars may behave differently on different platforms.   One
189       example  of this concerns the handling of checkbuttons and radiobuttons
190       within the menu.  While it is permitted to put these menu  elements  on
191       menubars,  they may not be drawn with indicators on some platforms, due
192       to system restrictions.
193
194   SPECIAL MENUS IN MENUBARS
195       Certain menus in a menubar will be treated specially.   On  the  Macin‐
196       tosh,  access to the special Application and Help menus is provided. On
197       Windows, access to the Windows System menu in each window is  provided.
198       On  X  Windows,  a special right-justified help menu may be provided if
199       Motif menu compatibility is enabled. In all cases, these menus must  be
200       created with the command name of the menubar menu concatenated with the
201       special name. So for a menubar named .menubar, on  the  Macintosh,  the
202       special  menus  would  be .menubar.apple and .menubar.help; on Windows,
203       the special menu would be .menubar.system; on X Windows, the help  menu
204       would be .menubar.help.
205
206       When  Tk  sees a .menubar.apple menu on the Macintosh, that menu's con‐
207       tents make up the first items of the Application menu whenever the win‐
208       dow  containing  the  menubar is in front.  After all of the Tk-defined
209       items, the menu will have a separator, followed by all standard  Appli‐
210       cation menu items.
211
212       When  Tk  sees  a  Help  menu on the Macintosh, the menu's contents are
213       appended to the standard Help menu on the right of the  user's  menubar
214       whenever  the window's menubar is in front. The first items in the menu
215       are provided by Mac OS X.
216
217       When Tk sees a System menu on Windows, its items are  appended  to  the
218       system menu that the menubar is attached to. This menu has an icon rep‐
219       resenting a spacebar, and can be invoked with the mouse  or  by  typing
220       Alt+Spacebar.  Due to limitations in the Windows API, any font changes,
221       colors, images, bitmaps, or tearoff images will not appear in the  sys‐
222       tem menu.
223
224       When  Tk  sees a Help menu on X Windows and Motif menu compatibility is
225       enabled the menu is moved to be last in the menubar and is right justi‐
226       fied.  Motif  menu  compatibility  is  enabled by setting the Tk option
227       *Menu.useMotifHelp to true or by calling tk::classic::restore menu.
228

CLONES

230       When a menu is set as a menubar for a toplevel window, or when  a  menu
231       is  torn  off, a clone of the menu is made. This clone is a menu widget
232       in its own right, but it is a child of the  original.  Changes  in  the
233       configuration of the original are reflected in the clone. Additionally,
234       any cascades that are pointed to are also cloned so that menu traversal
235       will  work  right.  Clones  are  destroyed  when  either the tearoff or
236       menubar goes away, or when the original menu is destroyed.
237

WIDGET COMMAND

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

DEFAULT BINDINGS

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

BUGS

685       At present it is not possible to use the  option  database  to  specify
686       values for the options to individual entries.
687

SEE ALSO

689       bind(n), menubutton(n), ttk::menubutton(n), toplevel(n)
690

KEYWORDS

692       menu, widget
693
694
695
696Tk                                    4.1                              menu(n)
Impressum