Charles.Forsyth20060303-partialeea662d19 years agoHistory
461 lines · 18.7 KB · Text
RawDownload
.TH MENU 9.SH NAMEmenu \- Create and manipulate menu widgets.SH SYNOPSIS\f5menu\fI \fIpathName \fR?\fIoptions\fR?.SH STANDARD OPTIONS.EX-activebackground -borderwidth   -foreground-activeforeground -disabledcolor -relief-background       -font.EE.SH "WIDGET-SPECIFIC OPTIONS".TP.B -postcommand \fIcommand\fPIf this option is specified then it provides a Tk command to executeeach time the menu is posted.  The command is invoked by the \f5post\fRwidget command before posting the menu..TP.B -selectcolor \fIcolour\fPFor menu entries that are check buttons or radio buttons, this optionspecifies the colour to display in the indicator when the check buttonor radio button is selected..SH INTRODUCTIONThe \f5menu\fR command creates a new top-level window (givenby the \fIpathName\fR argument) and makes it into a menu widget.Additionaloptions, described above, may be specified on the command lineto configure aspects of the menu such as its colours and font.The \f5menu\fR command returns its\fIpathName\fR argument.  At the time this command is invoked,there must not exist a window named \fIpathName\fR..PPA menu is a widget that displays a collection of one-line entries arrangedin a column.  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..PPMenu 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 \f5-label\fR,\f5-bitmap\fR, and \f5-image\fR options for the entry.The second field is a marker for cascade entries,showing that the entry will post a cascade menu.It is displayed at the right-hand edge of the entry.The third field is an \fIindicator\fR.  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..PPIn 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 is \fIinvoked\fR.The effect of invocation is different for each type of entry;these effects are described below in the sections on individualentries..PPEntries may be \fIdisabled\fR, which causes their labelsand accelerators to be displayedwith dimmer colours.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. .SH "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 Tk command is executed.  The Tkcommand is specified with the \f5-command\fR option. .SH "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 behaviour other than its display appearance. .SH "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, the value``1'' is stored in a particular global variable (as determined by\f5-variable\fR option for the entry);  whenthe entry is deselected the value ``0'' 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 colour given by the \f5-selectcolor\fR option for the entry;otherwise the indicator's center is displayed in the background colour forthe menu.  If a \f5-command\fR option is specified for a checkbuttonentry, then its value is evaluated as a Tk command each time the entryis invoked;  this happens after toggling the entry'sselected state. .SH "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 \f5-value\fR and\f5-variable\fR 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 colour given by the \f5-selectcolor\fR optionfor the entry;otherwise the indicator's center is displayed in the background colour forthe menu.  If a \f5-command\fR option is specified for a radiobuttonentry, then its value is evaluated as a Tk command each time the entryis invoked;  this happens after selecting the entry. .SH "CASCADE ENTRIES"A cascade entry is one with an associated menu (determinedby the \f5-menu\fR option).  Cascade entries allow the constructionof cascading menus.The \f5postcascade\fR widget command can be used to post and unpostthe associated menu just to the right 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)..PPA cascade entry posts its associated menu by invoking aTk command of the form.RS.EX\fImenu\f5 post \fIx y\fR.EE.REwhere \fImenu\fR is the path name of the associated menu, and \fIx\fRand \fIy\fR are the screen coordinates of the upper-rightcorner of the cascade entry.The lower-level menu is unposted by executing a Tk command withthe form.RS.EX\fImenu\f5 unpost\fR.EE.REwhere \fImenu\fR is the name of the associated menu..PPIf a \f5-command\fR option is specified for a cascade entry then it isevaluated as a Tk command whenever the entry is invoked. .SH "WIDGET COMMAND"The \f5menu\fR command creates a new Tk command whosename is \fIpathName\fR.  Thiscommand may be used to invoke variousoperations on the widget.  It has the following general form:.RS.EX\fIpathName option \fR?\fIarg arg ...\fR?.EE.RE\fIOption\fR and the \fIarg\fRsdetermine the exact behaviour of the command..PPMany of the widget commands for a menu take as one argument anindicator of which entry of the menu to operate on.  Theseindicators are called \fIindex\fRes and may be specified inany of the following forms:.TP 12\fInumber\fRSpecifies the entry numerically, where 0 correspondsto the top-most entry of the menu, 1 to the entry below it, andso on..TP 12\f5active\fRIndicates the entry that is currently active.  If no entry isactive then this form is equivalent to \f5none\fR.  This form maynot be abbreviated..TP 12\f5end\fRIndicates the bottommost entry in the menu.  If there are noentries in the menu then this form is equivalent to \f5none\fR.This form may not be abbreviated..TP 12\f5none\fRIndicates ``no entry at all'';  this is used most commonly withthe \f5activate\fR option to deactivate all the entries in themenu.  In most cases the specification of \f5none\fR causesnothing to happen in the widget command.This form may not be abbreviated..TP 12\f5@\fInumber\fRIn this form, \fInumber\fR is treated as a y-coordinate in themenu's window;  the entry closest to that y-coordinate is used.For example, ``\f5@0\fR'' indicates the top-most entry in thewindow..PPThe following widget commands are possible for menu widgets:.TP\fIpathName \f5activate \fIindex\fRChange the state of the entry indicated by \fIindex\fR to \f5active\fRand redisplay it using its active colours.Any previously-active entry is deactivated.  If \fIindex\fRis specified as \f5none\fR, or if the specified entry isdisabled, then the menu ends up with no active entry.Returns an empty string..TP\fIpathName \f5add \fItype \fR?\fIoption value option value ...\fR?Add a new entry to the bottom of the menu.  The new entry's typeis given by \fItype\fR and must be one of \f5cascade\fR,\f5checkbutton\fR, \f5command\fR, \f5radiobutton\fR, or \f5separator\fR.If additional argumentsare present, they specify any of the following options:.RS.TP\f5-activebackground \fIvalue\fRSpecifies a background colour to use for displaying this entry when itis active.If this option is not specified then the\f5activebackground\fR option for the overall menu is used.This option is not available for separator entries..TP\f5-activeforeground \fIvalue\fRSpecifies a foreground colour to use for displaying this entry when itis active.If this option is not specified then the\f5activeforeground\fR option for the overall menu is used.This option is not available for separator entries..TP\f5-background \fIvalue\fRSpecifies a background colour to use for displaying this entry when itis in the normal state (neither active nor disabled).If this option is not specified then the\f5background\fR option for the overall menu is used.This option is not available for separator entries..TP\f5-bitmap \fIbitmap\fRSpecifies a bitmap to display in the menu instead of a textuallabel.This option overrides the \f5-label\fR option but may be resetto an empty string to enable a textual label to be displayed.If a \f5-image\fR option has been specified, it overrides\f5-bitmap\fR.This option is not available for separator entries..TP\f5-command \fIvalue\fRSpecifies a Tk command to execute when the menu entry is invoked.Not available for separator entries..TP\f5-font \fIvalue\fRSpecifies the font to use when drawing the label or acceleratorstring in this entry.If this option is not specified thenthe \f5font\fR option for the overall menu is used.This option is not available for separator entries..TP\f5-foreground \fIvalue\fRSpecifies a foreground colour to use for displaying this entry when itis in the normal state (neither active nor disabled).If this option is not specified then the\f5foreground\fR option for the overall menu is used.This option is not available for separator entries..TP\f5-image \fIvalue\fRSpecifies an image to display in the menu instead of a text stringor bitmapThe image must have been created by some previous invocation of\f5image create\fR.This option overrides the \f5-label\fR and \f5-bitmap\fR optionsbut may be reset to an empty string to enable a textual orbitmap label to be displayed.This option is not available for separator entries..TP\f5-label \fIvalue\fRSpecifies a string to display as an identifying label in the menuentry.  Not available for separator entries..TP\f5-menu \fIvalue\fRAvailable only for cascade entries.  Specifies the path name ofthe submenu associated with this entry.The submenu must be a child of the menu..TP\f5-selectcolor \fIvalue\fRAvailable only for checkbutton and radiobutton entries.Specifies the colour to display in the indicator when the entry isselected.If this option is not specified then the \f5selectcolor\fRoption for the menu determines the indicator colour..TP\f5-selectimage \fIvalue\fRAvailable only for checkbutton and radiobutton entries.Specifies an image to display in the entry (in place ofthe \f5-image\fR option) when it is selected.\fIValue\fR is the name of an image, which must have been createdby some previous invocation of \f5image create\fR.This option is ignored unless the \f5-image\fR option hasbeen specified..TP\f5-state \fIvalue\fRSpecifies one of three states for the entry:  \f5normal\fR, \f5active\fR,or \f5disabled\fR.  In normal state the entry is displayed using the\f5foreground\fR and \f5background\fRcolours.The active state is typically used when the pointer is over the entry.In active state the entry is displayed using the \f5activeforeground\fRand \f5activebackground\fR colours.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 \f5disabledcolor\fR and \f5background\fR colours.This option is not available for separator entries..TP\f5-underline \fIvalue\fRSpecifies 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 entries..TP\f5-value \fIvalue\fRAvailable 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 \f5-label\fR optionfor the entry as the value to store in the variable..TP\f5-variable \fIvalue\fRAvailable only for checkbutton and radiobutton entries.  Specifiesthe name of a global value 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..LPThe \f5add\fR widget command returns an empty string..RE.TP\fIpathName \f5cget\fR \fIoption\fRReturns the current value of the configuration option givenby \fIoption\fR.\fIOption\fR may have any of the values accepted by the \f5menu\fRcommand..TP\fIpathName \f5configure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?Query or modify the configuration options of the widget.If no \fIoption\fR is specified, returns a list of all ofthe available options for \fIpathName\fR.  Ifone or more \fIoption-value\fR 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.\fIOption\fR may have any of the values accepted by the \f5menu\fRcommand..TP\fIpathName \f5delete \fIindex1\fR ?\fIindex2\fR?Delete all of the menu entries between \fIindex1\fR and\fIindex2\fR inclusive.If \fIindex2\fR is omitted then it defaults to \fIindex1\fR..TP\fIpathName \f5entrycget\fR \fIindex option\fRReturns the current value of a configuration option forthe entry given by \fIindex\fR.\fIOption\fR may have any of the values accepted by the \f5add\fRwidget command..TP\fIpathName \f5entryconfigure \fIindex \fR?\fIoptions\fR?This command is similar to the \f5configure\fR command, except thatit applies to the options for an individual entry, whereas \f5configure\fRapplies to the options for the menu as a whole.\fIOptions\fR may have any of the values accepted by the \f5add\fRwidget command.  If \fIoptions\fR are specified, options are modifiedas indicatedin the command and the command returns an empty string..TP\fIpathName \f5index \fIindex\fRReturns the numerical index corresponding to \fIindex\fR, or\f5none\fR if \fIindex\fR was specified as \f5none\fR..TP\fIpathName \f5insert \fIindex\fR \fItype \fR?\fIoption value option value ...\fR?Same as the \f5add\fR widget command except that it inserts the newentry just before the entry given by \fIindex\fR, instead of appendingto the end of the menu.  The \fItype\fR, \fIoption\fR, and \fIvalue\fRarguments have the same interpretation as for the \f5add\fR widgetcommand..TP\fIpathName \f5invoke \fIindex\fRInvoke 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 the \f5invoke\fR 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 the \f5invoke\fRwidget command..TP\fIpathName \f5post \fIx y\fRArrange for the menu to be displayed on the screen at the screencoordinates given by \fIx\fR and \fIy\fR.  These coordinates areadjusted if necessary to guarantee that the entire menu is visible onthe screen.  This command normally returns an empty string.If the \f5postcommand\fR option has been specified, then its value isexecuted as a Tk script before posting the menu and the result ofthat script is returned as the result of the \f5post\fR widgetcommand.If an error returns while executing the command, then the error isreturned without posting the menu..TP\fIpathName \f5postcascade \fIindex\fRPosts the submenu associated with the cascade entry given by\fIindex\fR, and unposts any previously posted submenu.If \fIindex\fR doesn't correspond to a cascade entry,or if \fIpathName\fR isn't posted,the command has no effect except to unpost any currently postedsubmenu..TP\fIpathName \f5type \fIindex\fRReturns the type of the menu entry given by \fIindex\fR.This is the \fItype\fR argument passed to the \f5add\fR widgetcommand when the entry was created, such as \f5command\fRor \f5separator\fR..TP\fIpathName \f5unpost\fRUnmap the window so that it is no longer displayed.  If alower-level cascaded menu is posted, unpost that menu.  Returns anempty string..TP\fIpathName \f5yposition \fIindex\fRReturns a decimal string giving the y-coordinate within the menuwindow of the topmost pixel in the entry specified by \fIindex\fR. .SH "DEFAULT BINDINGS"Tk automatically creates bindings for menus that give themthe following default behaviour:.IP [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..IP [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..IP [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..IP [4]If any of the entries in a menu have letters underlined withwith \f5-underline\fR option, then pressing one of the underlinedletters (or its upper-case or lower-case equivalent) invokes thatentry and unposts the menu..PPDisabled menu entries are non-responsive:  they don't activate andthey ignore mouse button presses and releases..PPThe behaviour of menus can be changed by defining new bindings forindividual widgets..SH BUGSThe first time any colour option of an entry is configured,all of the menu colour option values are captured and set in the entry.Any subsequent changes to the menu's colour optionswill not be reflected in the entry..SH SEE ALSO.IR options (9),.IR types (9)