Movatterモバイル変換


[0]ホーム

URL:


Tcl8.6.17/Tk8.6.17 Documentation>Tk Commands, version 8.6.17> menu

Tcl/Tk Applications |Tcl Commands |Tk Commands |[incr Tcl] Package Commands |SQLite3 Package Commands |TDBC Package Commands |tdbc::mysql Package Commands |tdbc::odbc Package Commands |tdbc::postgres Package Commands |tdbc::sqlite3 Package Commands |Thread Package Commands |Tcl C API |Tk C API |[incr Tcl] Package C API |TDBC Package C API

NAME
menu, tk_menuSetFocus — Create and manipulate 'menu' widgets and menubars
SYNOPSIS
STANDARD OPTIONS
-activebackground, activeBackground, Foreground
-activeborderwidth, activeBorderWidth, BorderWidth
-activeforeground, activeForeground, Background
-background or -bg, background, Background
-borderwidth or -bd, borderWidth, BorderWidth
-cursor, cursor, Cursor
-disabledforeground, disabledForeground, DisabledForeground
-font, font, Font
-foreground or -fg, foreground, Foreground
-relief, relief, Relief
-takefocus, takeFocus, TakeFocus
WIDGET-SPECIFIC OPTIONS
-postcommand, postCommand, Command
-selectcolor, selectColor, Background
-tearoff, tearOff, TearOff
-tearoffcommand, tearOffCommand, TearOffCommand
-title, title, Title
-type, type, Type
INTRODUCTION
TYPES OF ENTRIES
COMMAND ENTRIES
SEPARATOR ENTRIES
CHECKBUTTON ENTRIES
RADIOBUTTON ENTRIES
CASCADE ENTRIES
TEAR-OFF ENTRIES
MENUBARS
SPECIAL MENUS IN MENUBARS
CLONES
WIDGET COMMAND
active
end
last
none
@x,y
number
pattern
pathNameactivateindex
pathNameaddtype?option value option value ...?
pathNamecgetoption
pathNameclonenewPathname ?cloneType?
pathNameconfigure ?option? ?value option value ...?
pathNamedeleteindex1 ?index2?
pathNameentrycgetindex option
pathNameentryconfigureindex?options...?
pathNameindexindex
pathNameinsertindex type?option value option value ...?
pathNameinvokeindex
pathNamepostx y ?index?
pathNamepostcascadeindex
pathNametypeindex
pathNameunpost
pathNamexpositionindex
pathNameypositionindex
MENU ENTRY OPTIONS
-activebackgroundvalue
-activeforegroundvalue
-acceleratorvalue
-backgroundvalue
-bitmapvalue
-columnbreakvalue
-commandvalue
-compoundvalue
-fontvalue
-foregroundvalue
-hidemarginvalue
-imagevalue
-indicatoronvalue
-labelvalue
-menuvalue
-offvaluevalue
-onvaluevalue
-selectcolorvalue
-selectimagevalue
-statevalue
-underlinevalue
-valuevalue
-variablevalue
MENU CONFIGURATIONS
Pulldown Menus in Menubar
Pulldown Menus in Menu Buttons
Popup Menus
Option Menus
Torn-off Menus
DEFAULT BINDINGS
    BUGS
    SEE ALSO
    KEYWORDS

    NAME

    menu, tk_menuSetFocus — Create and manipulate 'menu' widgets and menubars

    SYNOPSIS

    menu pathName?options?
    tk_menuSetFocus pathName

    STANDARD OPTIONS

    -activebackground, activeBackground, Foreground
    -activeborderwidth, activeBorderWidth, BorderWidth
    -activeforeground, activeForeground, Background
    -background or -bg, background, Background
    -borderwidth or -bd, borderWidth, BorderWidth
    -cursor, cursor, Cursor
    -disabledforeground, disabledForeground, DisabledForeground
    -font, font, Font
    -foreground or -fg, foreground, Foreground
    -relief, relief, Relief
    -takefocus, takeFocus, TakeFocus

    WIDGET-SPECIFIC OPTIONS

    Command-Line Name:-postcommand
    Database Name:postCommand
    Database Class:Command
    If this option is specified then it provides a Tcl command to executeeach time the menu is posted. The command is invoked by thepostwidget command before posting the menu. Note that in Tk 8.0 on Macintoshand Windows, all post-commands in a system of menus are executed before anyof those menus are posted.This is due to the limitations in the individual platforms' menu managers.

    Command-Line Name:-selectcolor
    Database Name:selectColor
    Database Class:Background
    For menu entries that are check buttons or radio buttons, this optionspecifies the color to display in the indicator when the check buttonor radio button is selected.

    Command-Line Name:-tearoff
    Database Name:tearOff
    Database Class:TearOff
    This option must have a proper boolean value, which specifieswhether or not the menu should include a tear-off entry at thetop. If so, it will exist as entry 0 of the menu and the otherentries will number starting at 1. The defaultmenu bindings arrange for the menu to be torn off when the tear-offentry is invoked.This option is ignored under Aqua/macOS, where menus cannotbe torn off.

    Command-Line Name:-tearoffcommand
    Database Name:tearOffCommand
    Database Class:TearOffCommand
    If this option has a non-empty value, then it specifies a Tcl commandto invoke whenever the menu is torn off. The actual command willconsist of the value of this option, followed by a space, followedby the name of the menu window, followed by a space, followed bythe name of the name of the torn off menu window. For example, ifthe option's value is“a b”and menu.x.y is torn off tocreate a new menu.x.tearoff1, then the command“a b .x.y .x.tearoff1”will be invoked.This option is ignored under Aqua/macOS, where menus cannotbe torn off.

    Command-Line Name:-title
    Database Name:title
    Database Class:Title
    The string will be used to title the window created when this menu istorn off. If the title is NULL, then the window will have the titleof the menubutton or the text of the cascade item from which this menuwas invoked.

    Command-Line Name:-type
    Database Name:type
    Database Class:Type
    This option can be one ofmenubar,tearoff, ornormal, and is set when the menu is created. While the stringreturned by the configuration database will change if this option ischanged, this does not affect the menu widget's behavior. This is usedby the cloning mechanism and is not normally set outside of the Tklibrary.

    INTRODUCTION

    Themenu command creates a new top-level window (givenby thepathName argument) and makes it into a menu widget.That menu widget can either be used as a pop-up window or applied to atoplevel (with its-menu option) to make it into the menubar forthat toplevel.Additionaloptions, described above, may be specified on the command lineor in the option databaseto configure aspects of the menu such as its colors and font.Themenu command returns itspathName argument. At the time this command is invoked,there must not exist a window namedpathName, butpathName's parent must exist.

    A menu is a widget that displays a collection of one-line entries arrangedin one or more columns. There exist several different types of entries,each with different properties. Entries of different types may becombined in a single menu. Menu entries are not the same asentry widgets. In fact, menu entries are not even distinct widgets;the entire menu is one widget.

    Menu entries are displayed with up to three separate fields.The main field is a label in the form of a text string,a bitmap, or an image, controlled by the-label,-bitmap, and-image options for the entry.If the-accelerator option is specified for an entry then a secondtextual field is displayed to the right of the label. The acceleratortypically describes a keystroke sequence that may be used in theapplication to cause the same result as invoking the menu entry.This is a display option, it does not actually set the correspondingbinding (which can be achieved using thebind command).The third field is anindicator. The indicator is present only forcheckbutton or radiobutton entries. It indicates whether the entryis selected or not, and is displayed to the left of the entry'sstring.

    In normal use, an entry becomes active (displays itself differently)whenever the mouse pointer is over the entry. If a mousebutton is released over the entry then the entry isinvoked.The effect of invocation is different for each type of entry;these effects are described below in the sections on individualentries.

    Entries may bedisabled, which causes their labelsand accelerators to be displayedwith dimmer colors.The default menu bindings will not allowa disabled entry to be activated or invoked.Disabled entries may be re-enabled, at which point it becomespossible to activate and invoke them again.

    Whenever a menu's active entry is changed, a <<MenuSelect>> virtualevent is send to the menu. The active item can then be queried fromthe menu, and an action can be taken, such as settingcontext-sensitive help text for the entry.

    TYPES OF ENTRIES

    COMMAND ENTRIES

    The most common kind of menu entry is a command entry, whichbehaves much like a button widget. When a command entry isinvoked, a Tcl command is executed. The Tclcommand is specified with the-command option.

    SEPARATOR ENTRIES

    A separator is an entry that is displayed as a horizontal dividingline. A separator may not be activated or invoked, and it hasno behavior other than its display appearance.

    CHECKBUTTON ENTRIES

    A checkbutton menu entry behaves much like a checkbutton widget.When it is invoked it toggles back and forth between the selectedand deselected states. When the entry is selected, a particularvalue is stored in a particular global variable (as determined bythe-onvalue and-variable options for the entry); whenthe entry is deselected another value (determined by the-offvalue option) is stored in the global variable.An indicator box is displayed to the left of the label in a checkbuttonentry. If the entry is selected then the indicator's center is displayedin the color given by the-selectcolor option for the entry;otherwise the indicator's center is displayed in the background color forthe menu. If a-command option is specified for a checkbuttonentry, then its value is evaluated as a Tcl command each time the entryis invoked; this happens after toggling the entry'sselected state.

    RADIOBUTTON ENTRIES

    A radiobutton menu entry behaves much like a radiobutton widget.Radiobutton entries are organized in groups of which only oneentry may be selected at a time. Whenever a particular entrybecomes selected it stores a particular value into a particularglobal variable (as determined by the-value and-variable options for the entry). This actioncauses any previously-selected entry in the same groupto deselect itself.Once an entry has become selected, any change to the entry'sassociated variable will cause the entry to deselect itself.Grouping of radiobutton entries is determined by theirassociated variables: if two entries have the same associatedvariable then they are in the same group.An indicator diamond is displayed to the left of the label in eachradiobutton entry. If the entry is selected then the indicator'scenter is displayed in the color given by the-selectcolor optionfor the entry;otherwise the indicator's center is displayed in the background color forthe menu. If a-command option is specified for a radiobuttonentry, then its value is evaluated as a Tcl command each time the entryis invoked; this happens after selecting the entry.

    CASCADE ENTRIES

    A cascade entry is one with an associated menu (determinedby the-menu option). Cascade entries allow the constructionof cascading menus.Thepostcascade widget command can be used to post and unpostthe associated menu just next to of the cascade entry.The associated menu must be a child of the menu containingthe cascade entry (this is needed in order for menu traversal towork correctly).

    A cascade entry posts its associated menu by invoking aTcl command of the form

    menu postx y
    wheremenu is the path name of the associated menu, andxandy are the root-window coordinates of the upper-rightcorner of the cascade entry.On Unix, the lower-level menu is unposted by executing a Tcl command withthe form
    menu unpost
    wheremenu is the name of the associated menu.On other platforms, the platform's native code takes care of unposting themenu.

    If a-command option is specified for a cascade entry then it isevaluated as a Tcl command whenever the entry is invoked. This is notsupported on Windows.

    TEAR-OFF ENTRIES

    A tear-off entry appears at the top of the menu if enabled with the-tearoff option. It is not like other menu entries in thatit cannot be created with theadd widget command andcannot be deleted with thedelete widget command.When a tear-off entry is created it appears as a dashed line atthe top of the menu. Under the default bindings, invoking thetear-off entry causes a torn-off copy to be made of the menu andall of its submenus.

    MENUBARS

    Any menu can be set as a menubar for a toplevel window (seetoplevel command for syntax). On the Macintosh, whenever thetoplevel is in front, this menu's cascade items will appear in themenubar across the top of the main monitor. On Windows and Unix, thismenu's items will be displayed in a menubar across the top of thewindow. These menus will behave according to the interface guidelinesof their platforms. For every menu set as a menubar, a clone menu ismade. See theCLONES section for more information.

    As noted, menubars may behave differently on different platforms. Oneexample of this concerns the handling of checkbuttons and radiobuttonswithin the menu. While it is permitted to put these menu elements onmenubars, they may not be drawn with indicators on some platforms, dueto system restrictions.

    SPECIAL MENUS IN MENUBARS

    Certain menus in a menubar will be treated specially. On the Macintosh,access to the special Application, Window and Help menus is provided. OnWindows, access to the Windows System menu in each window is provided.On X Windows, a special right-justified help menu may be provided ifMotif menu compatibility is enabled. In all cases, these menus must becreated with the command name of the menubar menu concatenated with thespecial name. So for a menubar named .menubar, on the Macintosh, thespecial menus would be .menubar.apple, .menubar.window and .menubar.help;on Windows, the special menu would be .menubar.system; on X Windows,the help menu would be .menubar.help.

    When Tk sees a .menubar.apple menu as the first menu in a menubar on theMacintosh, that menu's contents make up the first items of theApplication menu whenever the window containing the menubar is in front.After all of the Tk-defined items, the menu will have a separator,followed by all standard Application menu items.Such a .apple menu must be present in a menu when that menu is firstconfigured as a toplevel's menubar, otherwise a default application menu(hidden from Tk) will be inserted into the menubar at that time andsubsequent addition of a .apple menu will no longer result in itbecoming the Application menu.

    When Tk sees a .menubar.window menu on the Macintosh, the menu'scontents are inserted into the standard Window menu of the user'smenubar whenever the window's menubar is in front. The first items inthe menu are provided by macOS, and the names of the currenttoplevels are automatically appended after all the Tk-defined items anda separator. The Window menu on the Mac also allows toggling thewindow into a fullscreen state, and managing a tabbed window interface(multiple windows grouped into a single window) if supported by thatversion of the operating system.

    When Tk sees a .menubar.help menu on the Macintosh, the menu's contentsare appended to the standard Help menu of the user's menubar wheneverthe window's menubar is in front. The first items in the menuare provided by macOS.

    When Tk sees a System menu on Windows, its items are appended to thesystem menu that the menubar is attached to. This menu is tied to theapplication icon and can be invoked with the mouse or by typingAlt+Spacebar. Due to limitations in the Windows API, any font changes,colors, images, bitmaps, or tearoff images will not appear in thesystem menu.

    When Tk sees a Help menu on X Windows and Motif menu compatibility isenabled the menu is moved to be last in the menubar and is rightjustified. Motif menu compatibility is enabled by setting the Tk option*Menu.useMotifHelp to true or by callingtk::classic::restore menu.

    CLONES

    When a menu is set as a menubar for a toplevel window, or when a menuis torn off, a clone of the menu is made. This clone is a menu widgetin its own right, but it is a child of the original. Changes in theconfiguration of the original are reflected in theclone. Additionally, any cascades that are pointed to are also clonedso that menu traversal will work right. Clones are destroyed wheneither the tearoff or menubar goes away, or when the original menu isdestroyed.

    WIDGET COMMAND

    Themenu command creates a new Tcl command whosename ispathName. Thiscommand may be used to invoke variousoperations on the widget. It has the following general form:
    pathName option?arg arg ...?
    Option and theargsdetermine the exact behavior of the command.

    Many of the widget commands for a menu take as one argument anindicator of which entry of the menu to operate on. Theseindicators are calledindexes and may be specified inany of the following forms:

    active
    Indicates the entry that is currently active. If no entry isactive then this form is equivalent tonone. This form maynot be abbreviated.

    end
    Indicates the bottommost entry in the menu. If there are noentries in the menu then this form is equivalent tonone.This form may not be abbreviated.

    last
    Same asend.

    none
    Indicates“no entry at all”;this is used most commonly withtheactivate option to deactivate all the entries in themenu. In most cases the specification ofnone causesnothing to happen in the widget command.This form may not be abbreviated.

    @x,y
    Indicates the entry that covers the point in the menu's window specifiedbyx andy (in pixel coordinates).If no entry covers that point, then this form is equivalent tonone.If only a single number is specified, it is treated as the y-coordinate.

    number
    Specifies the entry numerically, where 0 correspondsto the top-most entry of the menu, 1 to the entry below it, andso on.

    pattern
    If the index does not satisfy one of the above forms then thisform is used.Pattern is pattern-matched against the label ofeach entry in the menu, in order from the top down, until amatching entry is found. The rules ofstring matchare used.

    If the index could match more than one of the above forms, thenthe form earlier in the above list takes precedence.

    The following widget commands are possible for menu widgets:

    pathNameactivateindex
    Change the state of the entry indicated byindex toactiveand redisplay it using its active colors.Any previously-active entry is deactivated. Ifindexis specified asnone, or if the specified entry isdisabled, then the menu ends up with no active entry.Returns an empty string.

    pathNameaddtype?option value option value ...?
    Add a new entry to the bottom of the menu. The new entry's typeis given bytype and must be one ofcascade,checkbutton,command,radiobutton, orseparator,or a unique abbreviation of one of the above. If additional argumentsare present, they specify the options listed in theMENU ENTRY OPTIONSsection below.Theadd widget command returns an empty string.

    pathNamecgetoption
    Returns the current value of the configuration option givenbyoption.Option may have any of the values accepted by themenucommand.

    pathNameclonenewPathname ?cloneType?
    Makes a clone of the current menu namednewPathName. This cloneis a menu in its own right, but any changes to the clone arepropagated to the original menu and vice versa.cloneType can benormal,menubar, ortearoff. Should not normally becalled outside of the Tk library. See theCLONES section formore information.

    pathNameconfigure ?option? ?value option value ...?
    Query or modify the configuration options of the widget.If nooption is specified, returns a list describing all ofthe available options forpathName (seeTk_ConfigureInfo forinformation on the format of this list). Ifoption is specifiedwith novalue, then the command returns a list describing theone named option (this list will be identical to the correspondingsublist of the value returned if nooption is specified). Ifone or moreoption-value pairs are specified, then the commandmodifies the given widget option(s) to have the given value(s); inthis case the command returns an empty string.Option may have any of the values accepted by themenucommand.

    pathNamedeleteindex1 ?index2?
    Delete all of the menu entries betweenindex1 andindex2 inclusive.Ifindex2 is omitted then it defaults toindex1.Attempts to delete a tear-off menu entry are ignored (instead, youshould change the-tearoff option to remove the tear-off entry).

    pathNameentrycgetindex option
    Returns the current value of a configuration option forthe entry given byindex.Option may have any of the names described in theMENU ENTRY OPTIONS section below.

    pathNameentryconfigureindex?options...?
    This command is similar to theconfigure command, except thatit applies to the options for an individual entry, whereasconfigureapplies to the options for the menu as a whole.Options may have any of the values described in theMENU ENTRY OPTIONSsection below. Ifoptions are specified, options aremodified as indicated in the command and the command returns an empty string.If nooptions are specified, returns a list describingthe current options for entryindex (seeTk_ConfigureInfo forinformation on the format of this list).

    pathNameindexindex
    Returns the numerical index corresponding toindex, ornone ifindex was specified asnone.

    pathNameinsertindex type?option value option value ...?
    Same as theadd widget command except that it inserts the newentry just before the entry given byindex, instead of appendingto the end of the menu. Thetype,option, andvaluearguments have the same interpretation as for theadd widgetcommand. It is not possible to insert new menu entries before thetear-off entry, if the menu has one.

    pathNameinvokeindex
    Invoke the action of the menu entry. See the sections on theindividual entries above for details on what happens. If themenu entry is disabled then nothing happens. If theentry has a command associated with it then the result of thatcommand is returned as the result of theinvoke widgetcommand. Otherwise the result is an empty string. Note: invokinga menu entry does not automatically unpost the menu; the defaultbindings normally take care of this before invoking theinvokewidget command.

    pathNamepostx y ?index?
    Arrange for the menu to be displayed on the screen at the root-windowcoordinates given byx andy. If an index is specifiedthe menu will be located so that the entry with that index isdisplayed at the point. These coordinates are adjusted if necessary toguarantee that the entire menu is visible on the screen. This commandnormally returns an empty string. If the-postcommand optionhas been specified, then its value is executed as a Tcl script beforeposting the menu and the result of that script is returned as theresult of thepost widget command. If an error returns whileexecuting the command, then the error is returned without posting themenu.

    pathNamepostcascadeindex
    Posts the submenu associated with the cascade entry given byindex, and unposts any previously posted submenu.Ifindex does not correspond to a cascade entry,or ifpathName is not posted,the command has no effect except to unpost any currently postedsubmenu.

    pathNametypeindex
    Returns the type of the menu entry given byindex.This is thetype argument passed to theadd orinsert widgetcommand when the entry was created, such ascommandorseparator, ortearoff for a tear-off entry.

    pathNameunpost
    Unmap the window so that it is no longer displayed. If alower-level cascaded menu is posted, unpost that menu. Returns anempty string. This subcommand does not work on Windows and theMacintosh, as those platforms have their own way of unposting menus.

    pathNamexpositionindex
    Returns a decimal string giving the x-coordinate within the menuwindow of the leftmost pixel in the entry specified byindex.

    pathNameypositionindex
    Returns a decimal string giving the y-coordinate within the menuwindow of the topmost pixel in the entry specified byindex.

    MENU ENTRY OPTIONS

    The following options are allowed on menu entries. Most options are notsupported by all entry types.

    -activebackgroundvalue
    Specifies a background color to use for displaying this entry when itis active. This option is ignored on Aqua/macOS.If it is specified as an empty string (the default), then the-activebackground option for the overall menu is used.If thetk_strictMotif variable has been set to request strictMotif compliance, then this option is ignored and the-backgroundoption is used in its place.This option is not available for separator or tear-off entries.

    -activeforegroundvalue
    Specifies a foreground color to use for displaying this entry when itis active. This option is ignored on Aqua/macOS.If this option is specified as an empty string (the default), then the-activeforeground option for the overall menu is used.This option is not available for separator or tear-off entries.

    -acceleratorvalue
    Specifies a string to display at the right side of the menu entry.Normally describes an accelerator keystroke sequence that may beused to invoke the same function as the menu entry. This is a displayoption, it does not actually set the corresponding binding (which canbe achieved using thebind command). This option is not availablefor separator or tear-off entries.

    -backgroundvalue
    Specifies a background color to use for displaying this entry when itis in the normal state (neither active nor disabled).This option is ignored on Aqua/macOS.If it is specified as an empty string (the default), then the-background option for the overall menu is used.This option is not available for separator or tear-off entries.

    -bitmapvalue
    Specifies a bitmap to display in the menu instead of a textuallabel, in any of the forms accepted byTk_GetBitmap.This option overrides the-label option(as controlled by the-compound option)but may be resetto an empty string to enable a textual label to be displayed.If a-image option has been specified, it overrides-bitmap.This option is not available for separator or tear-off entries.

    -columnbreakvalue
    When this option is zero, the entry appears below the previous entry. Whenthis option is one, the entry appears at the top of a new column in themenu.This option is ignored on Aqua/macOS, where menus are always a singlecolumn.

    -commandvalue
    Specifies a Tcl command to execute when the menu entry is invoked.Not available for separator or tear-off entries.

    -compoundvalue
    Specifies whether the menu entry should display both an image and text,and if so, where the image should be placed relative to the text.Valid values for this option arebottom,center,left,none,right andtop. The default valueisnone, meaning that the button will display either an image ortext, depending on the values of the-image and-bitmapoptions.

    -fontvalue
    Specifies the font to use when drawing the label or acceleratorstring in this entry.If this option is specified as an empty string (the default) thenthe-font option for the overall menu is used.This option is not available for separator or tear-off entries.

    -foregroundvalue
    Specifies a foreground color to use for displaying this entry when itis in the normal state (neither active nor disabled).This option is ignored on Aqua/macOS.If it is specified as an empty string (the default), then the-foreground option for the overall menu is used.This option is not available for separator or tear-off entries.

    -hidemarginvalue
    Specifies whether the standard margins should be drawn for this menuentry. This is useful when creating palette with images in them, i.e.,color palettes, pattern palettes, etc. 1 indicates that the margin forthe entry is hidden; 0 means that the margin is used.

    -imagevalue
    Specifies an image to display in the menu instead of a text stringor bitmap.The image must have been created by some previous invocation ofimage create.This option overrides the-label and-bitmap options(as controlled by the-compound option)but may be reset to an empty string to enable a textual orbitmap label to be displayed.This option is not available for separator or tear-off entries.

    -indicatoronvalue
    Available only for checkbutton and radiobutton entries.Value is a boolean that determines whether or not theindicator should be displayed.

    -labelvalue
    Specifies a string to display as an identifying label in the menuentry. Not available for separator or tear-off entries.

    -menuvalue
    Available only for cascade entries. Specifies the path name ofthe submenu associated with this entry.The submenu must be a child of the menu.

    -offvaluevalue
    Available only for checkbutton entries. Specifies the value tostore in the entry's associated variable when the entry isdeselected.

    -onvaluevalue
    Available only for checkbutton entries. Specifies the value tostore in the entry's associated variable when the entry is selected.

    -selectcolorvalue
    Available only for checkbutton and radiobutton entries.Specifies the color to display in the indicator when the entry isselected.If the value is an empty string (the default) then the-selectcoloroption for the menu determines the indicator color.

    -selectimagevalue
    Available only for checkbutton and radiobutton entries.Specifies an image to display in the entry (in place ofthe-image option) when it is selected.Value is the name of an image, which must have been createdby some previous invocation ofimage create.This option is ignored unless the-image option hasbeen specified.

    -statevalue
    Specifies one of three states for the entry:normal,active,ordisabled. In normal state the entry is displayed using the-foreground option for the menu and the-backgroundoption from the entry or the menu.The active state is typically used when the pointer is over the entry.In active state the entry is displayed using the-activeforegroundoption for the menu along with the-activebackground option fromthe entry. Disabled state means that the entryshould be insensitive: the default bindings will refuse to activateor invoke the entry.In this state the entry is displayed according to the-disabledforeground option for the menu and the-background option from the entry.This option is not available for separator entries.

    -underlinevalue
    Specifies the integer index of a character to underline in the entry.This option is also queried by the default bindings and used toimplement keyboard traversal.0 corresponds to the first character of the text displayed in the entry,1 to the next character, and so on.If a bitmap or image is displayed in the entry then this option is ignored.This option is not available for separator or tear-off entries.

    -valuevalue
    Available only for radiobutton entries. Specifies the value tostore in the entry's associated variable when the entry is selected.If an empty string is specified, then the-label optionfor the entry as the value to store in the variable.

    -variablevalue
    Available only for checkbutton and radiobutton entries. Specifiesthe name of a global variable to set when the entry is selected.For checkbutton entries the variable is also set when the entryis deselected. For radiobutton entries, changing the variablecauses the currently-selected entry to deselect itself.

    For checkbutton entries, the default value of this option is taken from the-label option, and for radiobutton entries a single fixed value isused. It is recommended that you always set the-variable option whencreating either a checkbutton or a radiobutton.

    MENU CONFIGURATIONS

    The default bindings support four different ways of using menus:

    Pulldown Menus in Menubar
    This is the most common case. You create a menu widget that will become themenu bar. You then add cascade entries to this menu, specifying thepull down menus you wish to use in your menu bar. You then create allof the pulldowns. Once you have done this, specify the menu using the-menu option of the toplevel's widget command. See thetoplevel manual entry for details.

    Pulldown Menus in Menu Buttons
    This is the compatible way to do menu bars. You create one menubuttonwidget for each top-level menu, and typically you arrange a series ofmenubuttons in a row in a menubar window. You also create the top-level menusand any cascaded submenus, and tie them together with-menuoptions in menubuttons and cascade menu entries. The top-level menu mustbe a child of the menubutton, and each submenu must be a child of themenu that refers to it. Once you have done this, the default bindingswill allow users to traverse and invoke the tree of menus via itsmenubutton; see themenubutton manual entry for details.

    Popup Menus
    Popup menus typically post in response to a mouse button press orkeystroke. You create the popup menus and any cascaded submenus,then you call thetk_popup procedure at the appropriate timeto post the top-level menu.

    Option Menus
    An option menu consists of a menubutton with an associated menuthat allows you to select one of several values. The current valueis displayed in the menubutton and is also stored in a globalvariable. Use thetk_optionMenu procedure to create optionmenubuttons and their menus.

    Torn-off Menus
    You create a torn-off menu by invoking the tear-off entry atthe top of an existing menu. The default bindings will create a new menuthat is a copy of the original menu and leave it permanentlyposted as a top-level window. The torn-off menu behaves justthe same as the original menu.

    DEFAULT BINDINGS

    Tk automatically creates class bindings for menus that give themthe following default behavior:

    1. When the mouse enters a menu, the entry underneath the mousecursor activates; as the mouse moves around the menu, the activeentry changes to track the mouse.

    2. When the mouse leaves a menu all of the entries in the menudeactivate, except in the special case where the mouse moves froma menu to a cascaded submenu.

    3. When a button is released over a menu, the active entry (if any) is invoked.The menu also unposts unless it is a torn-off menu.

    4. The Space and Return keys invoke the active entry andunpost the menu.

    5. If any of the entries in a menu have letters underlined withthe-underline option, then pressing one of the underlinedletters (or its upper-case or lower-case equivalent) invokes thatentry and unposts the menu.

    6. The Escape key aborts a menu selection in progress without invoking anyentry. It also unposts the menu unless it is a torn-off menu.

    7. The Up and Down keys activate the next higher or lower entryin the menu. When one end of the menu is reached, the activeentry wraps around to the other end.

    8. The Left key moves to the next menu to the left.If the current menu is a cascaded submenu, then the submenu isunposted and the current menu entry becomes the cascade entryin the parent.If the current menu is a top-level menu posted from amenubutton, then the current menubutton is unposted and thenext menubutton to the left is posted.Otherwise the key has no effect.The left-right order of menubuttons is determined by their stackingorder: Tk assumes that the lowest menubutton (which by defaultis the first one created) is on the left.

    9. The Right key moves to the next menu to the right.If the current entry is a cascade entry, then the submenu isposted and the current menu entry becomes the first entryin the submenu.Otherwise, if the current menu was posted from amenubutton, then the current menubutton is unposted and thenext menubutton to the right is posted.

    Disabled menu entries are non-responsive: they do not activate andthey ignore mouse button presses and releases.

    Several of the bindings make use of the commandtk_menuSetFocus.It saves the current focus and sets the focus to itspathNameargument, which is a menu widget.

    The behavior of menus can be changed by defining new bindings forindividual widgets or by redefining the class bindings.

    BUGS

    At present it is not possible to use theoption database to specify values for the options to individualentries.

    SEE ALSO

    bind,menubutton,ttk::menubutton,toplevel

    KEYWORDS

    menu,widget
    Copyright © 1990-1994 The Regents of the University of California.
    Copyright © 1994-1997 Sun Microsystems, Inc.

    [8]ページ先頭

    ©2009-2025 Movatter.jp