Widget¶
Usage¶
This class exists only for actual widgets to inherit from; it should not be be instantiated directly.
Reference¶
Bases: Node, PackMixin, ABC
Source code in core/src/toga/widgets/base.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
DEBUG_LAYOUT_ENABLED = False
class-attribute
instance-attribute
¶
Determines whether debug layout mode is enabled.
When enabled, container widgets use distinct background colors to make the layout more visible and help identify issues during development.
See the Debugging Your App guide for more information.
app
property
writable
¶
The App to which this widget belongs.
When setting the app for a widget, all children of this widget will be recursively assigned to the same app.
:raises ValueError: If this widget is already associated with another app.
applicator = TogaApplicator()
instance-attribute
¶
enabled
property
writable
¶
Is the widget currently enabled? i.e., can the user interact with the widget?
factory
cached
property
¶
id
property
¶
A unique identifier for the widget (read-only).
tab_index
property
writable
¶
The position of the widget in the focus chain for the window.
Note
This is a beta feature. The tab_index API may change in the future.
window
property
writable
¶
__init__(id=None, style=None, **kwargs)
¶
Create a base Toga widget.
This is an abstract base class; it cannot be instantiated.
:param id: The ID for the widget. :param style: A style object. If no style is provided, a default style will be applied to the widget. :param kwargs: Initial style properties.
Source code in core/src/toga/widgets/base.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
__lt__(other)
¶
Source code in core/src/toga/widgets/base.py
150 151 | |
__repr__()
¶
Source code in core/src/toga/widgets/base.py
147 148 | |
add(*children)
¶
Add the provided widgets as children of this widget.
If a child widget already has a parent, it will be re-parented as a child of this widget. If the child widget is already a child of this widget, there is no change.
:param children: The widgets to add as children of this widget. :raises ValueError: If this widget cannot have children.
Source code in core/src/toga/widgets/base.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
clear()
¶
Remove all child widgets of this node.
Refreshes the widget after removal if any children were removed.
:raises ValueError: If this widget cannot have children.
Source code in core/src/toga/widgets/base.py
297 298 299 300 301 302 303 304 305 | |
focus()
¶
Give this widget the input focus.
This method is a no-op if the widget can't accept focus. The ability of a widget to accept focus is platform-dependent. In general, on desktop platforms you can focus any widget that can accept user input, while on mobile platforms focus is limited to widgets that accept text input (i.e., widgets that cause the virtual keyboard to appear).
Source code in core/src/toga/widgets/base.py
384 385 386 387 388 389 390 391 392 393 | |
index(child)
¶
Get the index of a widget in the list of children of this widget.
:param child: The child widget of interest. :raises ValueError: If the specified child widget is not found in the list of children.
:returns: Index of specified child widget in children list.
Source code in core/src/toga/widgets/base.py
243 244 245 246 247 248 249 250 251 252 253 254 255 | |
insert(index, child)
¶
Insert a widget as a child of this widget.
If a child widget already has a parent, it will be re-parented as a child of this widget. If the child widget is already a child of this widget, there is no change.
:param index: The position in the list of children where the new widget should be added. :param child: The child to insert as a child of this node. :raises ValueError: If this widget cannot have children.
Source code in core/src/toga/widgets/base.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
refresh()
¶
Source code in core/src/toga/widgets/base.py
370 371 372 373 374 375 376 377 378 379 380 381 382 | |
remove(*children)
¶
Remove the provided widgets as children of this node.
Any nominated child widget that is not a child of this widget will not have any change in parentage.
Refreshes the widget after removal if any children were removed.
:param children: The child nodes to remove. :raises ValueError: If this widget cannot have children.
Source code in core/src/toga/widgets/base.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
replace(old_child, new_child)
¶
Replace an existing child widget with a new child widget.
:param old_child: The existing child widget to be replaced. :param new_child: The new child widget to be included.
Source code in core/src/toga/widgets/base.py
257 258 259 260 261 262 263 264 265 | |
A type describing a style object. By default, this will be Pack, but Toga allows for other style representations.