| 1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| 2 |
<html> |
| 3 |
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ --> |
| 4 |
<head> |
| 5 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 6 |
<title>menubutton (GCL TK Manual)</title> |
| 7 |
|
| 8 |
<meta name="description" content="menubutton (GCL TK Manual)"> |
| 9 |
<meta name="keywords" content="menubutton (GCL TK Manual)"> |
| 10 |
<meta name="resource-type" content="document"> |
| 11 |
<meta name="distribution" content="global"> |
| 12 |
<meta name="Generator" content="makeinfo"> |
| 13 |
<link href="index.html" rel="start" title="Top"> |
| 14 |
<link href="wm.html#SEC_Contents" rel="contents" title="Table of Contents"> |
| 15 |
<link href="Widgets.html" rel="up" title="Widgets"> |
| 16 |
<link href="text.html" rel="next" title="text"> |
| 17 |
<link href="checkbutton.html" rel="prev" title="checkbutton"> |
| 18 |
<style type="text/css"> |
| 19 |
<!-- |
| 20 |
a.summary-letter {text-decoration: none} |
| 21 |
blockquote.indentedblock {margin-right: 0em} |
| 22 |
div.display {margin-left: 3.2em} |
| 23 |
div.example {margin-left: 3.2em} |
| 24 |
div.lisp {margin-left: 3.2em} |
| 25 |
kbd {font-style: oblique} |
| 26 |
pre.display {font-family: inherit} |
| 27 |
pre.format {font-family: inherit} |
| 28 |
pre.menu-comment {font-family: serif} |
| 29 |
pre.menu-preformatted {font-family: serif} |
| 30 |
span.nolinebreak {white-space: nowrap} |
| 31 |
span.roman {font-family: initial; font-weight: normal} |
| 32 |
span.sansserif {font-family: sans-serif; font-weight: normal} |
| 33 |
ul.no-bullet {list-style: none} |
| 34 |
--> |
| 35 |
</style> |
| 36 |
|
| 37 |
|
| 38 |
</head> |
| 39 |
|
| 40 |
<body lang="en"> |
| 41 |
<span id="menubutton"></span><div class="header"> |
| 42 |
<p> |
| 43 |
Next: <a href="text.html" accesskey="n" rel="next">text</a>, Previous: <a href="checkbutton.html" accesskey="p" rel="prev">checkbutton</a>, Up: <a href="Widgets.html" accesskey="u" rel="up">Widgets</a> [<a href="wm.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 44 |
</div> |
| 45 |
<hr> |
| 46 |
<span id="menubutton-1"></span><h3 class="section">2.8 menubutton</h3> |
| 47 |
|
| 48 |
<p>menubutton \- Create and manipulate menubutton widgets |
| 49 |
</p><span id="Synopsis-7"></span><h4 class="unnumberedsubsec">Synopsis</h4> |
| 50 |
<p><b>menubutton</b><i> </i><i>pathName </i><span class="roman">?</span><i>options</i>? |
| 51 |
</p><span id="Standard-Options-7"></span><h4 class="unnumberedsubsec">Standard Options</h4> |
| 52 |
|
| 53 |
|
| 54 |
<div class="example"> |
| 55 |
<pre class="example">activeBackground bitmap font relief |
| 56 |
activeForeground borderWidth foreground text |
| 57 |
anchor cursor padX textVariable |
| 58 |
background disabledForeground padY underline |
| 59 |
</pre></div> |
| 60 |
|
| 61 |
|
| 62 |
<p>See <a href="options.html">options</a>, for more information. |
| 63 |
</p><span id="Arguments-for-Menubutton"></span><h4 class="unnumberedsubsec">Arguments for Menubutton</h4> |
| 64 |
|
| 65 |
|
| 66 |
<dl compact="compact"> |
| 67 |
<dt><code><b>:height</b></code></dt> |
| 68 |
<dd><p align="right">Name=<code>"<b>height</b><span class="roman">"</span> Class=<code>"</code><b>Height</b>"</code> |
| 69 |
</p><br> |
| 70 |
|
| 71 |
<p>Specifies a desired height for the menu button. |
| 72 |
If a bitmap is being displayed in the menu button then the value is in |
| 73 |
screen units (i.e. any of the forms acceptable to <b>Tk_GetPixels</b>); |
| 74 |
for text it is in lines of text. |
| 75 |
If this option isn’t specified, the menu button’s desired height is computed |
| 76 |
from the size of the bitmap or text being displayed in it. |
| 77 |
</p></dd> |
| 78 |
</dl> |
| 79 |
|
| 80 |
|
| 81 |
<dl compact="compact"> |
| 82 |
<dt><code><b>:menu</b></code></dt> |
| 83 |
<dd><p align="right">Name=<code>"<b>menu</b><span class="roman">"</span> Class=<code>"</code><b>MenuName</b>"</code> |
| 84 |
</p><br> |
| 85 |
|
| 86 |
<p>Specifies the path name of the menu associated with this menubutton. |
| 87 |
The menu must be a descendant of the menubutton in order for normal pull-down |
| 88 |
operation to work via the mouse. |
| 89 |
</p></dd> |
| 90 |
</dl> |
| 91 |
|
| 92 |
|
| 93 |
<dl compact="compact"> |
| 94 |
<dt><code><b>:state</b></code></dt> |
| 95 |
<dd><p align="right">Name=<code>"<b>state</b><span class="roman">"</span> Class=<code>"</code><b>State</b>"</code> |
| 96 |
</p><br> |
| 97 |
|
| 98 |
<p>Specifies one of three states for the menu button: <b>normal</b><span class="roman">, </span><b>active</b>, |
| 99 |
or <b>disabled</b>. In normal state the menu button is displayed using the |
| 100 |
<b>foreground</b><span class="roman"> and </span><b>background</b> options. The active state is |
| 101 |
typically used when the pointer is over the menu button. In active state |
| 102 |
the menu button is displayed using the <b>activeForeground</b> and |
| 103 |
<b>activeBackground</b> options. Disabled state means that the menu button |
| 104 |
is insensitive: it doesn’t activate and doesn’t respond to mouse |
| 105 |
button presses. In this state the <b>disabledForeground</b> and |
| 106 |
<b>background</b> options determine how the button is displayed. |
| 107 |
</p></dd> |
| 108 |
</dl> |
| 109 |
|
| 110 |
|
| 111 |
<dl compact="compact"> |
| 112 |
<dt><code><b>:width</b></code></dt> |
| 113 |
<dd><p align="right">Name=<code>"<b>width</b><span class="roman">"</span> Class=<code>"</code><b>Width</b>"</code> |
| 114 |
</p><br> |
| 115 |
|
| 116 |
<p>Specifies a desired width for the menu button. |
| 117 |
If a bitmap is being displayed in the menu button then the value is in |
| 118 |
screen units (i.e. any of the forms acceptable to <b>Tk_GetPixels</b>); |
| 119 |
for text it is in characters. |
| 120 |
If this option isn’t specified, the menu button’s desired width is computed |
| 121 |
from the size of the bitmap or text being displayed in it. |
| 122 |
</p></dd> |
| 123 |
</dl> |
| 124 |
|
| 125 |
<span id="Introduction-4"></span><h4 class="unnumberedsubsec">Introduction</h4> |
| 126 |
|
| 127 |
<p>The <b>menubutton</b> command creates a new window (given by the |
| 128 |
<i>pathName</i> argument) and makes it into a menubutton widget. |
| 129 |
Additional |
| 130 |
options, described above, may be specified on the command line |
| 131 |
or in the option database |
| 132 |
to configure aspects of the menubutton such as its colors, font, |
| 133 |
text, and initial relief. The <b>menubutton</b> command returns its |
| 134 |
<i>pathName</i> argument. At the time this command is invoked, |
| 135 |
there must not exist a window named <i>pathName</i>, but |
| 136 |
<i>pathName</i>’s parent must exist. |
| 137 |
</p> |
| 138 |
<p>A menubutton is a widget that displays a |
| 139 |
textual string or bitmap |
| 140 |
and is associated with a menu widget. In normal usage, pressing |
| 141 |
mouse button 1 over the menubutton causes the associated menu to |
| 142 |
be posted just underneath the menubutton. If the mouse is moved over |
| 143 |
the menu before releasing the mouse button, the button release |
| 144 |
causes the underlying menu entry to be invoked. When the button |
| 145 |
is released, the menu is unposted. |
| 146 |
</p> |
| 147 |
<p>Menubuttons are typically organized into groups called menu bars |
| 148 |
that allow scanning: |
| 149 |
if the mouse button is pressed over one menubutton (causing it |
| 150 |
to post its menu) and the mouse is moved over another menubutton |
| 151 |
in the same menu bar without releasing the mouse button, then the |
| 152 |
menu of the first menubutton is unposted and the menu of the |
| 153 |
new menubutton is posted instead. |
| 154 |
The <b>tk-menu-bar</b> procedure is used to set up menu bars for |
| 155 |
scanning; see that procedure for more details. |
| 156 |
</p> |
| 157 |
<span id="A-Menubutton-Widget_0027s-Arguments"></span><h4 class="unnumberedsubsec">A Menubutton Widget’s Arguments</h4> |
| 158 |
|
| 159 |
<p>The <b>menubutton</b> command creates a new Tcl command whose |
| 160 |
name is <i>pathName</i>. This |
| 161 |
command may be used to invoke various |
| 162 |
operations on the widget. It has the following general form: |
| 163 |
</p> |
| 164 |
<div class="example"> |
| 165 |
<pre class="example"><i>pathName option </i><span class="roman">?</span><i>arg arg ...</i>? |
| 166 |
</pre></div> |
| 167 |
|
| 168 |
<p><i>Option</i><span class="roman"> and the </span><i>arg</i>s |
| 169 |
determine the exact behavior of the command. The following |
| 170 |
commands are possible for menubutton widgets: |
| 171 |
</p> |
| 172 |
<dl compact="compact"> |
| 173 |
<dt><i>pathName </i><b>:activate</b></dt> |
| 174 |
<dd><p>Change the menu button’s state to <b>active</b> and redisplay the menu |
| 175 |
button using its active foreground and background colors instead of normal |
| 176 |
colors. |
| 177 |
The command returns an empty string. |
| 178 |
This command is ignored if the menu button’s state is <b>disabled</b>. |
| 179 |
This command is obsolete and will eventually be removed; |
| 180 |
use “<i>pathName </i><b>:configure :state active</b>” instead. |
| 181 |
</p></dd> |
| 182 |
<dt><i>pathName </i><b>:configure</b><span class="roman"> ?</span><i>option</i><span class="roman">? ?</span><i>value option value ...</i>?</dt> |
| 183 |
<dd><p>Query or modify the configuration options of the widget. |
| 184 |
If no <i>option</i> is specified, returns a list describing all of |
| 185 |
the available options for <i>pathName</i><span class="roman"> (see </span><b>Tk_ConfigureInfo</b> for |
| 186 |
information on the format of this list). If <i>option</i> is specified |
| 187 |
with no <i>value</i>, then the command returns a list describing the |
| 188 |
one named option (this list will be identical to the corresponding |
| 189 |
sublist of the value returned if no <i>option</i> is specified). If |
| 190 |
one or more <i>option:value</i> pairs are specified, then the command |
| 191 |
modifies the given widget option(s) to have the given value(s); in |
| 192 |
this case the command returns an empty string. |
| 193 |
<i>Option</i><span class="roman"> may have any of the values accepted by the </span><b>menubutton</b> |
| 194 |
command. |
| 195 |
</p></dd> |
| 196 |
<dt><i>pathName </i><b>:deactivate</b></dt> |
| 197 |
<dd><p>Change the menu button’s state to <b>normal</b> and redisplay the menu |
| 198 |
button using its normal foreground and background colors. |
| 199 |
The command returns an empty string. |
| 200 |
This command is ignored if the menu button’s state is <b>disabled</b>. |
| 201 |
This command is obsolete and will eventually be removed; |
| 202 |
use “<i>pathName </i><b>:configure :state normal</b>” instead. |
| 203 |
</p> |
| 204 |
</dd> |
| 205 |
</dl> |
| 206 |
<span id="g_t_0022Default-Bindings_0022-2"></span><h4 class="unnumberedsubsec">"Default Bindings"</h4> |
| 207 |
|
| 208 |
|
| 209 |
<p>Tk automatically creates class bindings for menu buttons that give them |
| 210 |
the following default behavior: |
| 211 |
</p><ul class="no-bullet"> |
| 212 |
<li> [1] |
| 213 |
A menu button activates whenever the mouse passes over it and deactivates |
| 214 |
whenever the mouse leaves it. |
| 215 |
</li><li> [2] |
| 216 |
A menu button’s relief is changed to raised whenever mouse button 1 is |
| 217 |
pressed over it, and the relief is restored to its original value |
| 218 |
when button 1 is later released or the mouse is dragged into another |
| 219 |
menu button in the same menu bar. |
| 220 |
</li><li> [3] |
| 221 |
When mouse button 1 is pressed over a menu button, or when the mouse |
| 222 |
is dragged into a menu button with mouse button 1 pressed, the associated |
| 223 |
menu is posted; the mouse can be dragged across the menu and released |
| 224 |
over an entry in the menu to invoke that entry. The menu is unposted |
| 225 |
when button 1 is released outside either the menu or the menu button. |
| 226 |
The menu is also unposted when the mouse is dragged into another |
| 227 |
menu button in the same menu bar. |
| 228 |
</li><li> [4] |
| 229 |
If mouse button 1 is pressed and released within the menu button, |
| 230 |
then the menu stays posted and keyboard traversal is possible as |
| 231 |
described in the manual entry for <b>tk-menu-bar</b>. |
| 232 |
</li><li> [5] |
| 233 |
Menubuttons may also be posted by typing characters on the keyboard. |
| 234 |
See the manual entry for <b>tk-menu-bar</b> for full details on keyboard |
| 235 |
menu traversal. |
| 236 |
</li><li> [6] |
| 237 |
If mouse button 2 is pressed over a menu button then the associated |
| 238 |
menu is posted and also <i>torn off</i>: it can then be dragged around on |
| 239 |
the screen with button 2 and the menu will not automatically unpost when |
| 240 |
entries in it are invoked. |
| 241 |
To close a torn off menu, click mouse button 1 over the associated |
| 242 |
menu button. |
| 243 |
</li></ul> |
| 244 |
|
| 245 |
<p>If the menu button’s state is <b>disabled</b> then none of the above |
| 246 |
actions occur: the menu button is completely non-responsive. |
| 247 |
</p> |
| 248 |
<p>The behavior of menu buttons can be changed by defining new bindings for |
| 249 |
individual widgets or by redefining the class bindings. |
| 250 |
</p> |
| 251 |
<span id="Keywords-7"></span><h4 class="unnumberedsubsec">Keywords</h4> |
| 252 |
<p>menubutton, widget |
| 253 |
</p><hr> |
| 254 |
<div class="header"> |
| 255 |
<p> |
| 256 |
Next: <a href="text.html" accesskey="n" rel="next">text</a>, Previous: <a href="checkbutton.html" accesskey="p" rel="prev">checkbutton</a>, Up: <a href="Widgets.html" accesskey="u" rel="up">Widgets</a> [<a href="wm.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 257 |
</div> |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
</body> |
| 262 |
</html> |