| 1 | |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta name="description" content="Pmw - a toolkit for building high-level compound widgets in Python"> |
| 5 | <meta name="content" content="python, megawidget, mega widget, compound widget, gui, tkinter"> |
| 6 | <title>Pmw.ButtonBox reference manual</title> |
| 7 | </head> |
| 8 | |
| 9 | <body bgcolor="#ffffff" text="#000000" link="#0000ee" |
| 10 | vlink="551a8b" alink="ff0000"> |
| 11 | |
| 12 | <h1 ALIGN="CENTER">Pmw.ButtonBox</h1> |
| 13 | |
| 14 | <center><IMG SRC=ButtonBox.gif ALT="" WIDTH=297 HEIGHT=65></center> |
| 15 | <dl> |
| 16 | <dt> <h3>Name</h3></dt><dd> |
| 17 | <p>Pmw.ButtonBox() - |
| 18 | manager megawidget for buttons |
| 19 | </p> |
| 20 | |
| 21 | |
| 22 | </dd> |
| 23 | <dt> <h3>Inherits</h3></dt><dd> |
| 24 | <a href="MegaWidget.html">Pmw.MegaWidget</a><br> |
| 25 | </dd> |
| 26 | <dt> <h3>Description</h3></dt><dd> |
| 27 | <p> |
| 28 | A button box is a container megawidget which manages a number of |
| 29 | buttons. One of these buttons may be specified as the default and |
| 30 | it will be displayed with the platform specific appearance for a |
| 31 | default button. The buttons may be laid out either horizontally |
| 32 | or vertically.</p> |
| 33 | |
| 34 | <p></p> |
| 35 | |
| 36 | |
| 37 | </dd> |
| 38 | <dt> <h3>Options</h3></dt><dd> |
| 39 | Options for this megawidget and its base |
| 40 | classes are described below.<p></p> |
| 41 | <a name=option.labelmargin></a> |
| 42 | <dl><dt> <strong>labelmargin |
| 43 | </strong></dt><dd> |
| 44 | Initialisation option. If the <strong>labelpos</strong> option is not <strong>None</strong>, this specifies the |
| 45 | distance between the <strong>label</strong> component and the rest of the |
| 46 | megawidget. The default is <strong>0</strong>.</p> |
| 47 | |
| 48 | |
| 49 | </dd></dl> |
| 50 | <a name=option.labelpos></a> |
| 51 | <dl><dt> <strong>labelpos |
| 52 | </strong></dt><dd> |
| 53 | Initialisation option. Specifies where to place the <strong>label</strong> component. If not |
| 54 | <strong>None</strong>, it should be a concatenation of one or two of the |
| 55 | letters <strong>'n'</strong>, <strong>'s'</strong>, <strong>'e'</strong> and <strong>'w'</strong>. The first letter |
| 56 | specifies on which side of the megawidget to place the label. |
| 57 | If a second letter is specified, it indicates where on that |
| 58 | side to place the label. For example, if <strong>labelpos</strong> is <strong>'w'</strong>, |
| 59 | the label is placed in the center of the left hand side; if |
| 60 | it is <strong>'wn'</strong>, the label is placed at the top of the left |
| 61 | hand side; if it is <strong>'ws'</strong>, the label is placed at the |
| 62 | bottom of the left hand side.</p> |
| 63 | <p> If <strong>None</strong>, a label component is not created. The default is <strong>None</strong>.</p> |
| 64 | |
| 65 | |
| 66 | |
| 67 | </dd></dl> |
| 68 | <a name=option.orient></a> |
| 69 | <dl><dt> <strong>orient |
| 70 | </strong></dt><dd> |
| 71 | Initialisation option. Specifies the orientation of the button box. This may be |
| 72 | <strong>'horizontal'</strong> or <strong>'vertical'</strong>. The default is <strong>'horizontal'</strong>.</p> |
| 73 | |
| 74 | |
| 75 | </dd></dl> |
| 76 | <a name=option.padx></a> |
| 77 | <dl><dt> <strong>padx |
| 78 | </strong></dt><dd> |
| 79 | Initialisation option. Specifies a padding distance to leave between each button in the x |
| 80 | direction and also between the buttons and the outer edge of the |
| 81 | button box. The default is <strong>3</strong>.</p> |
| 82 | |
| 83 | |
| 84 | </dd></dl> |
| 85 | <a name=option.pady></a> |
| 86 | <dl><dt> <strong>pady |
| 87 | </strong></dt><dd> |
| 88 | Initialisation option. Specifies a padding distance to leave between each button in the y |
| 89 | direction and also between the buttons and the outer edge of the |
| 90 | button box. The default is <strong>3</strong>.</p> |
| 91 | |
| 92 | |
| 93 | </dd></dl> |
| 94 | </dd> |
| 95 | <dt> <h3>Components</h3></dt><dd> |
| 96 | Components created by this megawidget and its base |
| 97 | classes are described below.<p></p> |
| 98 | <a name=component.frame></a> |
| 99 | <dl><dt> <strong>frame |
| 100 | </strong></dt><dd> |
| 101 | If the <strong>label</strong> component has been created (that is, the <strong>labelpos</strong> |
| 102 | option is not <strong>None</strong>), the <strong>frame</strong> component is created to act as |
| 103 | the container of the buttons created by the <code>add()</code> and |
| 104 | <code>insert()</code> methods. If there is no <strong>label</strong> component, then no |
| 105 | <strong>frame</strong> component is created and the <strong>hull</strong> component acts as the |
| 106 | container. By default, this component is a Tkinter.Frame.</p> |
| 107 | |
| 108 | |
| 109 | </dd></dl> |
| 110 | <a name=component.hull></a> |
| 111 | <dl><dt> <strong>hull |
| 112 | </strong></dt><dd> |
| 113 | This acts as the body for the entire megawidget. Other components |
| 114 | are created as children of the hull to further specialise this |
| 115 | class. By default, this component is a Tkinter.Frame.</p> |
| 116 | |
| 117 | |
| 118 | </dd></dl> |
| 119 | <a name=component.label></a> |
| 120 | <dl><dt> <strong>label |
| 121 | </strong></dt><dd> |
| 122 | If the <strong>labelpos</strong> option is not <strong>None</strong>, this component is |
| 123 | created as a text label for the megawidget. See the |
| 124 | <strong>labelpos</strong> option for details. Note that to set, for example, |
| 125 | the <strong>text</strong> option of the label, you need to use the <strong>label_text</strong> |
| 126 | component option. By default, this component is a Tkinter.Label.</p> |
| 127 | |
| 128 | |
| 129 | </dd></dl> |
| 130 | </dd> |
| 131 | <dt> <h3>Dynamic components</h3></dt><dd> |
| 132 | <p> |
| 133 | Button components are created dynamically by the <code>add()</code> and |
| 134 | <code>insert()</code> methods. By default, the buttons are of type |
| 135 | Tkinter.Button and are created with a component group of |
| 136 | <strong>Button</strong>.</p> |
| 137 | <p> </p> |
| 138 | |
| 139 | |
| 140 | |
| 141 | </dd> |
| 142 | <a name=methods></a> |
| 143 | <dt> <h3>Methods</h3></dt><dd> |
| 144 | Only methods specific to this megawidget are described below. |
| 145 | For a description of its inherited methods, see the |
| 146 | manual for its base class |
| 147 | <strong><a href="MegaWidget.html#methods">Pmw.MegaWidget</a></strong>. |
| 148 | <p></p> |
| 149 | <a name=method.add></a> |
| 150 | <dl><dt> <strong>add</strong>(<em>componentName</em>, **<em>kw</em>)</dt><dd> |
| 151 | Add a button to the end of the button box as a component named |
| 152 | <em>componentName</em>. Any keyword arguments present will be passed to the |
| 153 | constructor when creating the button. If the <strong>text</strong> keyword |
| 154 | argument is not given, the <strong>text</strong> option of the button defaults to |
| 155 | <em>componentName</em>. The method returns the component widget.</p> |
| 156 | |
| 157 | |
| 158 | </dd></dl> |
| 159 | <a name=method.alignbuttons></a> |
| 160 | <dl><dt> <strong>alignbuttons</strong>(<em>when</em> = <strong>'later'</strong>)</dt><dd> |
| 161 | Set the widths of all the buttons to be the same as the width of |
| 162 | the widest button. If <em>when</em> is <strong>'later'</strong>, this will occur when the |
| 163 | interpreter next becomes idle, otherwise the resizing will occur |
| 164 | immediately.</p> |
| 165 | |
| 166 | |
| 167 | </dd></dl> |
| 168 | <a name=method.button></a> |
| 169 | <dl><dt> <strong>button</strong>(<em>buttonIndex</em>)</dt><dd> |
| 170 | Return the button specified by <em>buttonIndex</em>, which may have any |
| 171 | of the forms accepted by the <code>index()</code> method.</p> |
| 172 | |
| 173 | |
| 174 | </dd></dl> |
| 175 | <a name=method.delete></a> |
| 176 | <dl><dt> <strong>delete</strong>(<em>index</em>)</dt><dd> |
| 177 | Delete the button given by <em>index</em> from the button box. <em>index</em> |
| 178 | may have any of the forms accepted by the <code>index()</code> method.</p> |
| 179 | |
| 180 | |
| 181 | </dd></dl> |
| 182 | <a name=method.index></a> |
| 183 | <dl><dt> <strong>index</strong>(<em>index</em>, <em>forInsert</em> = <strong>0</strong>)</dt><dd> |
| 184 | Return the numerical index of the button corresponding to <em>index</em>. |
| 185 | This may be specified in any of the following forms:</p> |
| 186 | <dl><dt><em>name</em></dt><dd>Specifies the button named <em>name</em>.<p></p> |
| 187 | |
| 188 | </dd> |
| 189 | <dt><em>number</em></dt><dd>Specifies the button numerically, where <strong>0</strong> corresponds to |
| 190 | the left (or top) button.<p></p> |
| 191 | |
| 192 | </dd> |
| 193 | <dt><strong>Pmw.END</strong></dt><dd>Specifies the right (or bottom) button.<p></p> |
| 194 | |
| 195 | </dd> |
| 196 | <dt><strong>Pmw.DEFAULT</strong></dt><dd>Specifies the current default button.<p></p> |
| 197 | |
| 198 | </dd></dl> |
| 199 | <p> If <em>forInsert</em> is true, <strong>Pmw.END</strong> returns the number of buttons rather |
| 200 | than the index of the last button.</p> |
| 201 | |
| 202 | |
| 203 | |
| 204 | </dd></dl> |
| 205 | <a name=method.insert></a> |
| 206 | <dl><dt> <strong>insert</strong>(<em>componentName</em>, <em>beforeComponent</em> = <strong>0</strong>, **<em>kw</em>)</dt><dd> |
| 207 | Add a button to the button box as a component named |
| 208 | <em>componentName</em>. The button is added just before the button |
| 209 | specified by <em>beforeComponent</em>, which may have any of the forms |
| 210 | accepted by the <code>index()</code> method. Any keyword arguments present |
| 211 | will be passed to the constructor when creating the button. If |
| 212 | the <strong>text</strong> keyword argument is not given, the <strong>text</strong> option of the |
| 213 | button defaults to <em>componentName</em>. To add a button to the end of |
| 214 | the button box, use <code>add()</code>. The method returns the component |
| 215 | widget.</p> |
| 216 | |
| 217 | |
| 218 | </dd></dl> |
| 219 | <a name=method.invoke></a> |
| 220 | <dl><dt> <strong>invoke</strong>(<em>index</em> = <strong>Pmw.DEFAULT</strong>, <em>noFlash</em> = <strong>0</strong>)</dt><dd> |
| 221 | Invoke the callback command associated with the button specified |
| 222 | by <em>index</em> and return the value returned by the callback. |
| 223 | Unless <em>noFlash</em> is true, flash the button to |
| 224 | indicate to the user that something happened. |
| 225 | <em>index</em> may have any of the forms accepted by the <code>index()</code> method.</p> |
| 226 | |
| 227 | |
| 228 | </dd></dl> |
| 229 | <a name=method.numbuttons></a> |
| 230 | <dl><dt> <strong>numbuttons</strong>()</dt><dd> |
| 231 | Return the number of buttons in the button box.</p> |
| 232 | |
| 233 | |
| 234 | </dd></dl> |
| 235 | <a name=method.setdefault></a> |
| 236 | <dl><dt> <strong>setdefault</strong>(<em>index</em>)</dt><dd> |
| 237 | Set the default button to the button given by <em>index</em>. This |
| 238 | causes the specified button to be displayed with the platform |
| 239 | specific appearance for a default button. If <em>index</em> is <strong>None</strong>, |
| 240 | there will be no default button. <em>index</em> may have any of the |
| 241 | forms accepted by the <code>index()</code> method.</p> |
| 242 | |
| 243 | |
| 244 | </dd></dl> |
| 245 | </dd> |
| 246 | <dt> <h3>Example</h3></dt><dd> |
| 247 | The image at the top of this manual is a snapshot |
| 248 | of the window (or part of the window) produced |
| 249 | by the following code.<p></p> |
| 250 | <pre> |
| 251 | class Demo: |
| 252 | def __init__(self, parent): |
| 253 | # Create and pack the ButtonBox. |
| 254 | self.buttonBox = Pmw.ButtonBox(parent, |
| 255 | labelpos = 'nw', |
| 256 | label_text = 'ButtonBox:', |
| 257 | frame_borderwidth = 2, |
| 258 | frame_relief = 'groove') |
| 259 | self.buttonBox.pack(fill = 'both', expand = 1, padx = 10, pady = 10) |
| 260 | |
| 261 | # Add some buttons to the ButtonBox. |
| 262 | self.buttonBox.add('OK', command = self.ok) |
| 263 | self.buttonBox.add('Apply', command = self.apply) |
| 264 | self.buttonBox.add('Cancel', command = self.cancel) |
| 265 | |
| 266 | # Set the default button (the one executed when <Return> is hit). |
| 267 | self.buttonBox.setdefault('OK') |
| 268 | parent.bind('<Return>', self._processReturnKey) |
| 269 | parent.focus_set() |
| 270 | |
| 271 | # Make all the buttons the same width. |
| 272 | self.buttonBox.alignbuttons() |
| 273 | |
| 274 | def _processReturnKey(self, event): |
| 275 | self.buttonBox.invoke() |
| 276 | |
| 277 | def ok(self): |
| 278 | print 'You clicked on OK' |
| 279 | |
| 280 | def apply(self): |
| 281 | print 'You clicked on Apply' |
| 282 | |
| 283 | def cancel(self): |
| 284 | print 'You clicked on Cancel' |
| 285 | |
| 286 | </pre> |
| 287 | </dd> |
| 288 | </dl> |
| 289 | |
| 290 | <center><P ALIGN="CENTER"> |
| 291 | <IMG SRC = blue_line.gif ALT = "" WIDTH=320 HEIGHT=5> |
| 292 | </p></center> |
| 293 | |
| 294 | |
| 295 | <font size=-1> |
| 296 | <center><P ALIGN="CENTER"> |
| 297 | Pmw 1.2 - |
| 298 | 5 Aug 2003 |
| 299 | - <a href="index.html">Home</a> |
| 300 | <br>Manual page last reviewed: 24 May 1998 |
| 301 | </p></center> |
| 302 | </font> |
| 303 | |
| 304 | </body> |
| 305 | </html> |
| 306 | |