| 1 |
# Copyright (c) 1990-1994 The Regents of the University of California. |
| 2 |
# Copyright (c) 1994-1996 Sun Microsystems, Inc. |
| 3 |
# See the file "license.terms" for information on usage and redistribution |
| 4 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 5 |
# |
| 6 |
# |
| 7 |
|
| 8 |
=head1 NAME |
| 9 |
|
| 10 |
Tk::Radiobutton - Create and manipulate Radiobutton widgets |
| 11 |
|
| 12 |
=for category Tk Widget Classes |
| 13 |
|
| 14 |
=head1 SYNOPSIS |
| 15 |
|
| 16 |
I<$radiobutton> = I<$parent>-E<gt>B<Radiobutton>(?I<options>?); |
| 17 |
|
| 18 |
=head1 STANDARD OPTIONS |
| 19 |
|
| 20 |
B<-activebackground> |
| 21 |
B<-activeforeground> |
| 22 |
B<-anchor> |
| 23 |
B<-background> |
| 24 |
B<-bitmap> |
| 25 |
B<-borderwidth> |
| 26 |
B<-compound> |
| 27 |
B<-cursor> |
| 28 |
B<-disabledforeground> |
| 29 |
B<-font> |
| 30 |
B<-foreground> |
| 31 |
B<-highlightbackground> |
| 32 |
B<-highlightcolor> |
| 33 |
B<-highlightthickness> |
| 34 |
B<-image> |
| 35 |
B<-justify> |
| 36 |
B<-padx> |
| 37 |
B<-pady> |
| 38 |
B<-relief> |
| 39 |
B<-takefocus> |
| 40 |
B<-text> |
| 41 |
B<-textvariable> |
| 42 |
B<-underline> |
| 43 |
B<-wraplength> |
| 44 |
|
| 45 |
See L<Tk::options> for details of the standard options. |
| 46 |
|
| 47 |
=head1 WIDGET-SPECIFIC OPTIONS |
| 48 |
|
| 49 |
=over 4 |
| 50 |
|
| 51 |
=item Name: B<command> |
| 52 |
|
| 53 |
=item Class: B<Command> |
| 54 |
|
| 55 |
=item Switch: B<-command> |
| 56 |
|
| 57 |
Specifies a L<perlE<sol>Tk callback|Tk::callbacks> to associate with the button. This command |
| 58 |
is typically invoked when mouse button 1 is released over the button |
| 59 |
window. The button's global variable (B<-variable> option) will |
| 60 |
be updated before the command is invoked. |
| 61 |
|
| 62 |
=item Name: B<height> |
| 63 |
|
| 64 |
=item Class: B<Height> |
| 65 |
|
| 66 |
=item Switch: B<-height> |
| 67 |
|
| 68 |
Specifies a desired height for the button. |
| 69 |
If an image or bitmap is being displayed in the button then the value is in |
| 70 |
screen units (i.e. any of the forms acceptable to B<Tk_GetPixels>); |
| 71 |
for text it is in lines of text. |
| 72 |
If this option isn't specified, the button's desired height is computed |
| 73 |
from the size of the image or bitmap or text being displayed in it. |
| 74 |
|
| 75 |
=item Name: B<indicatorOn> |
| 76 |
|
| 77 |
=item Class: B<IndicatorOn> |
| 78 |
|
| 79 |
=item Switch: B<-indicatoron> |
| 80 |
|
| 81 |
Specifies whether or not the indicator should be drawn. Must be a |
| 82 |
proper boolean value. If false, the B<relief> option is |
| 83 |
ignored and the widget's relief is always sunken if the widget is |
| 84 |
selected and raised otherwise. |
| 85 |
|
| 86 |
=item Command-Line Name: B<-offrelief> |
| 87 |
|
| 88 |
=item Database Name: B<offRelief> |
| 89 |
|
| 90 |
=item Database Class: B<OffRelief> |
| 91 |
|
| 92 |
Specifies the relief for the checkbutton when the indicator is not |
| 93 |
drawn and the checkbutton is off. The default value is B<raised>. By |
| 94 |
setting this option to B<flat> and setting |
| 95 |
B<-indicatoron false -overrelief raised>, the effect is achieved of |
| 96 |
having a flat button |
| 97 |
that raises on mouse-over and which is depressed when activated. This |
| 98 |
is the behavior typically exhibited by the Bold, Italic, and |
| 99 |
Underline checkbuttons on the toolbar of a word-processor, for |
| 100 |
example. |
| 101 |
|
| 102 |
=item Command-Line Name: B<-overrelief> |
| 103 |
|
| 104 |
=item Database Name: B<overRelief> |
| 105 |
|
| 106 |
=item Database Class: B<OverRelief> |
| 107 |
|
| 108 |
Specifies an alternative relief for the button, to be used when |
| 109 |
the mouse cursor is over the widget. This option can be used to |
| 110 |
make toolbar buttons, by configuring B<-relief flat -overrelief |
| 111 |
raised>. If the value of this option is the empty string, then |
| 112 |
no alternative relief is used when the mouse cursor is over the |
| 113 |
button. The empty string is the default value. |
| 114 |
|
| 115 |
=item Name: B<selectColor> |
| 116 |
|
| 117 |
=item Class: B<Background> |
| 118 |
|
| 119 |
=item Switch: B<-selectcolor> |
| 120 |
|
| 121 |
Specifies a background color to use when the button is selected. |
| 122 |
If B<indicatorOn> is true then the color applies to the indicator. |
| 123 |
Under Windows, this color is used as the background for the indicator |
| 124 |
regardless of the select state. |
| 125 |
If B<indicatorOn> is false, this color is used as the background |
| 126 |
for the entire widget, in place of B<background> or B<activeBackground>, |
| 127 |
whenever the widget is selected. |
| 128 |
If specified as an empty string then no special color is used for |
| 129 |
displaying when the widget is selected. |
| 130 |
|
| 131 |
=item Name: B<selectImage> |
| 132 |
|
| 133 |
=item Class: B<SelectImage> |
| 134 |
|
| 135 |
=item Switch: B<-selectimage> |
| 136 |
|
| 137 |
Specifies an image to display (in place of the B<image> option) |
| 138 |
when the radiobutton is selected. |
| 139 |
This option is ignored unless the B<image> option has been |
| 140 |
specified. |
| 141 |
|
| 142 |
=item Name: B<state> |
| 143 |
|
| 144 |
=item Class: B<State> |
| 145 |
|
| 146 |
=item Switch: B<-state> |
| 147 |
|
| 148 |
Specifies one of three states for the radiobutton: B<normal>, B<active>, |
| 149 |
or B<disabled>. In normal state the radiobutton is displayed using the |
| 150 |
B<foreground> and B<background> options. The active state is |
| 151 |
typically used when the pointer is over the radiobutton. In active state |
| 152 |
the radiobutton is displayed using the B<activeForeground> and |
| 153 |
B<activeBackground> options. Disabled state means that the radiobutton |
| 154 |
should be insensitive: the default bindings will refuse to activate |
| 155 |
the widget and will ignore mouse button presses. |
| 156 |
In this state the B<disabledForeground> and |
| 157 |
B<background> options determine how the radiobutton is displayed. |
| 158 |
|
| 159 |
=item Name: B<value> |
| 160 |
|
| 161 |
=item Class: B<Value> |
| 162 |
|
| 163 |
=item Switch: B<-value> |
| 164 |
|
| 165 |
Specifies value to store in the button's associated variable whenever |
| 166 |
this button is selected. |
| 167 |
|
| 168 |
=item Name: B<variable> |
| 169 |
|
| 170 |
=item Class: B<Variable> |
| 171 |
|
| 172 |
=item Switch: B<-variable> |
| 173 |
|
| 174 |
Specifies reference to a variable to set whenever this button is |
| 175 |
selected. Changes in this variable also cause the button to select |
| 176 |
or deselect itself. Defaults to the value C<\$Tk::selectedButton>. |
| 177 |
|
| 178 |
=item Name: B<width> |
| 179 |
|
| 180 |
=item Class: B<Width> |
| 181 |
|
| 182 |
=item Switch: B<-width> |
| 183 |
|
| 184 |
Specifies a desired width for the button. |
| 185 |
If an image or bitmap is being displayed in the button, the value is in |
| 186 |
screen units (i.e. any of the forms acceptable to B<Tk_GetPixels>); |
| 187 |
for text it is in characters. |
| 188 |
If this option isn't specified, the button's desired width is computed |
| 189 |
from the size of the image or bitmap or text being displayed in it. |
| 190 |
|
| 191 |
=back |
| 192 |
|
| 193 |
=head1 DESCRIPTION |
| 194 |
|
| 195 |
The B<Radiobutton> method creates a new window (given by the |
| 196 |
$widget argument) and makes it into a radiobutton widget. |
| 197 |
Additional |
| 198 |
options, described above, may be specified on the command line |
| 199 |
or in the option database |
| 200 |
to configure aspects of the radiobutton such as its colors, font, |
| 201 |
text, and initial relief. The B<radiobutton> command returns its |
| 202 |
$widget argument. At the time this command is invoked, |
| 203 |
there must not exist a window named $widget, but |
| 204 |
$widget's parent must exist. |
| 205 |
|
| 206 |
A radiobutton is a widget that displays a textual string, bitmap or image |
| 207 |
and a diamond or circle called an I<indicator>. |
| 208 |
If text is displayed, it must all be in a single font, but it |
| 209 |
can occupy multiple lines on the screen (if it contains newlines |
| 210 |
or if wrapping occurs because of the B<wrapLength> option) and |
| 211 |
one of the characters may optionally be underlined using the |
| 212 |
B<underline> option. A radiobutton has |
| 213 |
all of the behavior of a simple button: it can display itself in either |
| 214 |
of three different ways, according to the B<state> option; |
| 215 |
it can be made to appear |
| 216 |
raised, sunken, or flat; it can be made to flash; and it invokes |
| 217 |
a L<perlE<sol>Tk callback|Tk::callbacks> whenever mouse button 1 is clicked over the |
| 218 |
check button. |
| 219 |
|
| 220 |
In addition, radiobuttons can be I<selected>. |
| 221 |
If a radiobutton is selected, the indicator is normally |
| 222 |
drawn with a selected appearance, and |
| 223 |
a Tcl variable associated with the radiobutton is set to a particular |
| 224 |
value (normally 1). |
| 225 |
Under Unix, the indicator is drawn with a sunken relief and a special |
| 226 |
color. Under Windows, the indicator is drawn with a round mark inside. |
| 227 |
If the radiobutton is not selected, then the indicator is drawn with a |
| 228 |
deselected appearance, and the associated variable is |
| 229 |
set to a different value (typically 0). |
| 230 |
Under Unix, the indicator is drawn with a raised relief and no special |
| 231 |
color. Under Windows, the indicator is drawn without a round mark inside. |
| 232 |
Typically, several radiobuttons share a single variable and the |
| 233 |
value of the variable indicates which radiobutton is to be selected. |
| 234 |
When a radiobutton is selected it sets the value of the variable to |
| 235 |
indicate that fact; each radiobutton also monitors the value of |
| 236 |
the variable and automatically selects and deselects itself when the |
| 237 |
variable's value changes. |
| 238 |
By default the variable B<selectedButton> |
| 239 |
is used; its contents give the name of the button that is |
| 240 |
selected, or the empty string if no button associated with that |
| 241 |
variable is selected. |
| 242 |
The name of the variable for a radiobutton, |
| 243 |
plus the variable to be stored into it, may be modified with options |
| 244 |
on the command line or in the option database. |
| 245 |
Configuration options may also be used to modify the way the |
| 246 |
indicator is displayed (or whether it is displayed at all). |
| 247 |
By default a radiobutton is configured to select itself on button clicks. |
| 248 |
|
| 249 |
=head1 WIDGET METHODS |
| 250 |
|
| 251 |
The B<Radiobutton> method creates a widget object. |
| 252 |
This object supports the B<configure> and B<cget> methods |
| 253 |
described in L<Tk::options> which can be used to enquire and |
| 254 |
modify the options described above. |
| 255 |
The widget also inherits all the methods provided by the generic |
| 256 |
L<Tk::Widget|Tk::Widget> class. |
| 257 |
|
| 258 |
The following additional methods are available for radiobutton widgets: |
| 259 |
|
| 260 |
=over 4 |
| 261 |
|
| 262 |
=item I<$radiobutton>-E<gt>B<deselect> |
| 263 |
|
| 264 |
Deselects the radiobutton and sets the associated variable to an |
| 265 |
empty string. |
| 266 |
If this radiobutton was not currently selected, the command has |
| 267 |
no effect. |
| 268 |
|
| 269 |
=item I<$radiobutton>-E<gt>B<flash> |
| 270 |
|
| 271 |
Flashes the radiobutton. This is accomplished by redisplaying the radiobutton |
| 272 |
several times, alternating between active and normal colors. At |
| 273 |
the end of the flash the radiobutton is left in the same normal/active |
| 274 |
state as when the command was invoked. |
| 275 |
This command is ignored if the radiobutton's state is B<disabled>. |
| 276 |
|
| 277 |
=item I<$radiobutton>-E<gt>B<invoke> |
| 278 |
|
| 279 |
Does just what would have happened if the user invoked the radiobutton |
| 280 |
with the mouse: selects the button and invokes |
| 281 |
its associated Tcl command, if there is one. |
| 282 |
The return value is the return value from the Tcl command, or an |
| 283 |
empty string if there is no command associated with the radiobutton. |
| 284 |
This command is ignored if the radiobutton's state is B<disabled>. |
| 285 |
|
| 286 |
=item I<$radiobutton>-E<gt>B<select> |
| 287 |
|
| 288 |
Selects the radiobutton and sets the associated variable to the |
| 289 |
value corresponding to this widget. |
| 290 |
|
| 291 |
=back |
| 292 |
|
| 293 |
=head1 BINDINGS |
| 294 |
|
| 295 |
Tk automatically creates class bindings for radiobuttons that give them |
| 296 |
the following default behavior: |
| 297 |
|
| 298 |
=over 4 |
| 299 |
|
| 300 |
=item [1] |
| 301 |
|
| 302 |
On Unix systems, a radiobutton activates whenever the mouse passes |
| 303 |
over it and deactivates whenever the mouse leaves the radiobutton. On |
| 304 |
Mac and Windows systems, when mouse button 1 is pressed over a |
| 305 |
radiobutton, the button activates whenever the mouse pointer is inside |
| 306 |
the button, and deactivates whenever the mouse pointer leaves the |
| 307 |
button. |
| 308 |
|
| 309 |
=item [2] |
| 310 |
|
| 311 |
When mouse button 1 is pressed over a radiobutton it is invoked (it |
| 312 |
becomes selected and the command associated with the button is |
| 313 |
invoked, if there is one). |
| 314 |
|
| 315 |
=item [3] |
| 316 |
|
| 317 |
When a radiobutton has the input focus, the space key causes the radiobutton |
| 318 |
to be invoked. |
| 319 |
|
| 320 |
If the radiobutton's state is B<disabled> then none of the above |
| 321 |
actions occur: the radiobutton is completely non-responsive. |
| 322 |
|
| 323 |
The behavior of radiobuttons can be changed by defining new bindings for |
| 324 |
individual widgets or by redefining the class bindings. |
| 325 |
|
| 326 |
=back |
| 327 |
|
| 328 |
=head1 KEYWORDS |
| 329 |
|
| 330 |
radiobutton, widget |
| 331 |
|
| 332 |
=cut |
| 333 |
|