📄 menubar.n
字号:
If \fImenuPathName\fR is of type \fBEntry\fR, the new component inserted is of type \fBentry\fR and given the name \fIname\fR. In this case, valid \fIoption\fR \fIvalue\fR pairs are those accepted by menu entries.\fIName\fR cannot be one of the keywords \fBlast\fR, \fBmenu\fR, \fBend\fR. Additionally, it may not be a number. However the \fImenuPathName\fR may be referenced in this manner (see discussion of \fBCOMPONENT PATH NAMES\fR)..TP\fIpathName\fR \fBinvoke\fR \fImenuPathName\fRInvoke the action of the menu entry denoted by \fImenuPathName\fR. See the sections on the individual entries in the menu(1) man pages. If the menu entry is disabled then nothing happens. If the entry has a command associated with it then the result of that command is returned as the result of the \fBinvoke\fR widget command. Otherwise the result is an empty string.If \fImenuPathName\fR is not a menu entry, an error is issued..TP\fIpathName\fR \fBmenucget\fR \fImenuPathName\fR \fIoption\fRReturns the current value of the configuration option given by \fIoption\fR. The component type of \fImenuPathName\fR determines the valid available options..TP\fIpathName\fR \fBmenuconfigure\fR \fImenuPathName\fR ?\fIoption\fR \fIvalue\fR?Query or modify the configuration options of the componet of the menubar specified by \fImenuPathName\fR. If no \fIoption\fR is specified, returns a list describing all of the available options for \fImenuPathName\fR (see \fBTk_ConfigureInfo\fR for information on the format of this list). If \fIoption\fR is specified with no value, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if no option is specified). If one or more option-value pairs are specified, then the command modifies the given widget option(s) to have the given value(s); in this case the command returns an empty string. The component type of \fImenuPathName\fR determines the valid available options..TP\fIpathName\fR \fBpath\fR ?\fImode\fR? \fIpattern\fRReturns a fully formed \fImenuPathName\fR that matches \fIpattern\fR. If no match is found it returns -1. The \fImode\fR argument indicates how the search is to be matched against \fIpattern\fR and it must have one of the following values:.RS.TP\fB-glob\fRPattern is a glob-style pattern which is matched against each component path using the same rules as the string match command..TP\fB-regexp\fRPattern is treated as a regular expression and matched against each component of the \fImenuPathName\fR using the same rules as the regexp command.The default mode is -glob..RE.TP\fIpathName\fR \fBtype\fR \fImenuPathName\fRReturns the type of the component specified by \fImenuPathName\fR. For menu entries, this is the type argument passed to the \fBadd\fR/\fBinsert\fR widget command when the entry was created, such as \fBcommand\fR or \fBseparator\fR. Othewise it is either a \fBmenubutton\fR or a \fBmenu\fR..TP\fIpathName\fR \fByposition\fR \fImenuPathName\fRReturns a decimal string giving the y-coordinate within the menu window of the topmost pixel in the entry specified by \fImenuPathName\fR. If the \fImenuPathName\fR is not an entry, an error is issued..SH "EXAMPLE ONE: USING GRAMMAR".PPThe following example creates a menubar with "File", "Edit", "Options" menubuttons. Each of these menubuttons has an associated menu. In turn the File menu has menu entries, as well as the Editmenu and the Options menu. The Options menu is a tearoff menuwith selectColor (for radiobuttons) set to blue.In addition, the Options menu has a cascade titled More,with several menu entries attached to it as well. An entry widget is provided to display help status..PPmenubar .mb -helpvariable helpVar -menubuttons { menubutton file -text File -menu { options -tearoff false command new -label New \\ -helpstr "Open new document" \\ -command {puts NEW} command close -label Close \\ -helpstr "Close current document" \\ -command {puts CLOSE} separator sep1 command exit -label Exit -command {exit} \\ -helpstr "Exit application" } menubutton edit -text Edit -menu { options -tearoff false command undo -label Undo -underline 0 \\ -helpstr "Undo last command" \\ -command {puts UNDO} separator sep2 command cut -label Cut -underline 1 \\ -helpstr "Cut selection to clipboard" \\ -command {puts CUT} command copy -label Copy -underline 1 \\ -helpstr "Copy selection to clipboard" \\ -command {puts COPY} command paste -label Paste -underline 0 \\ -helpstr "Paste clipboard contents" \\ -command {puts PASTE} } menubutton options -text Options -menu { options -tearoff false -selectcolor blue radiobutton byName -variable viewMode \\ -value NAME -label "by Name" \\ -helpstr "View files by name order" \\ -command {puts NAME} radiobutton byDate -variable viewMode \\ -value DATE -label "by Date" \\ -helpstr "View files by date order" \\ -command {puts DATE} cascade prefs -label Preferences -menu { command colors -label Colors... \\ -helpstr "Change text colors" \\ -command {puts COLORS} command fonts -label Fonts... \\ -helpstr "Change text font" \\ -command {puts FONT} } }}.if.nfframe .fr -width 300 -height 300entry .ef -textvariable helpVarpack .mb -anchor nw -fill x -expand yespack .fr -fill both -expand yespack .ef -anchor sw -fill x -expand yes.if.SH "EXAMPLE TWO: USING METHODS"Alternatively the same menu could be created by using the add and configure methods:.PP.nf.ta 2c 4c 6c 8c 10c 12c 14c 16c menubar .mb .mb configure -menubuttons { menubutton file -text File -menu { command new -label New command close -label Close separator sep1 command quit -label Quit } menubutton edit -text Edit }.if.PP .mb add command .edit.undo -label Undo -underline 0 .mb add separator .edit.sep2 .mb add command .edit.cut -label Cut -underline 1 .mb add command .edit.copy -label Copy -underline 1 .mb add command .edit.paste -label Paste -underline 0 .mb add menubutton .options -text Options -menu { radiobutton byName -variable viewMode \\ -value NAME -label "by Name" radiobutton byDate -variable viewMode \\ -value DATE -label "by Date"} .mb add cascade .options.prefs -label Preferences -menu { command colors -label Colors... command fonts -label Fonts... } pack .mb -side left -anchor nw -fill x -expand yes.SH CAVEATSThe \fB-menubuttons\fR option as well as the \fB-menu\fR option is evaluated by menubar with the \fBsubst\fR command. The positive side of this is that the option string may contain variables, commands, and/or backslash substitutions. However, substitutions might expand into more than a single word. These expansions can be protected by enclosing candidate substitutions in curly braces ({}). This ensures, for example, a value for an option will still be treated as a single value and not multiple values. The following example illustrates this case:.nf.IP.ta 2c 4c 6cset fileMenuName "File Menu"set var {}menubar .mb -menubuttons { menubutton file -text {$fileMenuName} menubutton edit -text Edit -menu { checkbutton check \\ -label Check \\ -variable {[scope var]} \\ -onvalue 1 \\ -offvalue 0 } menubutton options -text Options}.fi.IPThe variable \fIfileMenuName\fR will expand to "File Menu" when the \fBsubst\fR command is used on the menubutton specification. In addition, the [\fBscope\fR...] command will expand to @scope :: var. By enclosing these inside {} they stay as a single value. Note that only {} work for this. [list...], "" etc. will not protect these from the subst command..SH ACKNOWLEDGMENTS.LPBret Schumaker.IP1994 - Early work on a menubar widget..LPMark Ulferts, Mark Harrison, John Sigler.IPInvaluable feedback on grammar and usability of the menubar widget.LP.SH AUTHORBill W. Scott.SH KEYWORDSframe, menu, menubutton, entries, help
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -