Colors
A class that defines the color scheme for a theme as well as provides several static methods for manipulating colors.
A Colors object is attached to a ThemeDefinition and can also
be accessed through the Style.colors property for the
current theme.
Examples:
```python
style = Style()
# dot-notation
style.colors.primary
# get method
style.colors.get('primary')
```
This class is an iterator, so you can iterate over the main
style color labels (primary, secondary, success, info, warning,
danger):
```python
for color_label in style.colors:
color = style.colors.get(color_label)
print(color_label, color)
```
If, for some reason, you need to iterate over all theme color
labels, then you can use the `Colors.label_iter` method. This
will include all theme colors.
```python
for color_label in style.colors.label_iter():
color = Colors.get(color_label)
print(color_label, color)
```
If you want to adjust the hsv values of an existing color by a
specific percentage (delta), you can use the `Colors.update_hsv`
method, which is static. In the example below, the "value delta"
or `vd` is increased by 15%, which will lighten the color:
```python
Colors.update_hsv("#9954bb", vd=0.15)
```
Source code in src/ttkbootstrap/style.py
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 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 | |
__init__(primary, secondary, success, info, warning, danger, light, dark, bg, fg, selectbg, selectfg, border, inputfg, inputbg, active)
Parameters:
primary (str):
The primary theme color; used by default for all widgets.
secondary (str):
An accent color; commonly of a `grey` hue.
success (str):
An accent color; commonly of a `green` hue.
info (str):
An accent color; commonly of a `blue` hue.
warning (str):
An accent color; commonly of an `orange` hue.
danger (str):
An accent color; commonly of a `red` hue.
light (str):
An accent color.
dark (str):
An accent color.
bg (str):
Background color.
fg (str):
Default text color.
selectfg (str):
The color of selected text.
selectbg (str):
The background color of selected text.
border (str):
The color used for widget borders.
inputfg (str):
The text color for input widgets.
inputbg (str):
The text background color for input widgets.
active (str):
An accent color.
Source code in src/ttkbootstrap/style.py
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 | |
get(color_label)
Lookup a color value from the color name
Parameters:
color_label (str):
A color label corresponding to a class propery
Returns:
str:
A hexadecimal color value.
Source code in src/ttkbootstrap/style.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
get_contrast_ration(lum1, lum2)
Calculate the contrast ratio between two luminance values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lum1
|
float
|
The first luminance value. |
required |
lum2
|
float
|
The second luminance value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
The contrast ratio. |
Source code in src/ttkbootstrap/style.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
get_foreground(color_label)
Return the appropriate foreground color for the specified color_label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color_label
|
str
|
A color label corresponding to a class property |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
A hexadecimal color value for the foreground color. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the color_label is not a valid color property. |
Source code in src/ttkbootstrap/style.py
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 | |
get_luminance(color)
Calculate the luminance of a color.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color
|
str
|
A hexadecimal color value. |
required |
Returns: float: The luminance value of the color.
Source code in src/ttkbootstrap/style.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
hex_to_rgb(color)
staticmethod
Convert hexadecimal color to rgb color value
Parameters:
color (str):
A hexadecimal color value
Returns:
tuple[int, int, int]:
An rgb color value.
Source code in src/ttkbootstrap/style.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | |
label_iter()
staticmethod
Iterate over all color label properties in the Color class
Returns:
iter:
An iterator for color label names
Source code in src/ttkbootstrap/style.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
make_transparent(alpha, foreground, background='#ffffff')
staticmethod
Simulate color transparency.
Parameters:
alpha (float):
The amount of transparency; a number between 0 and 1.
foreground (str):
The foreground color.
background (str):
The background color.
Returns:
str:
A hexadecimal color representing the "transparent"
version of the foreground color against the background
color.
Source code in src/ttkbootstrap/style.py
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 | |
rgb_to_hex(r, g, b)
staticmethod
Convert rgb to hexadecimal color value
Parameters:
r (int):
red
g (int):
green
b (int):
blue
Returns:
str:
A hexadecimal color value
Source code in src/ttkbootstrap/style.py
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | |
rgb_to_hsv(r, g, b)
staticmethod
Convert an rgb to hsv color value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
float
|
red |
required |
g
|
float
|
green |
required |
b
|
float
|
blue |
required |
Returns:
| Type | Description |
|---|---|
|
tuple[float, float, float]: The hsv color value. |
Source code in src/ttkbootstrap/style.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
set(color_label, color_value)
Set a color property value. This does not update any existing widgets. Can also be used to create on-demand color properties that can be used in your program after creation.
Parameters:
color_label (str):
The name of the color to be set (key)
color_value (str):
A hexadecimal color value
Source code in src/ttkbootstrap/style.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |
update_hsv(color, hd=0, sd=0, vd=0)
staticmethod
Modify the hue, saturation, and/or value of a given hex color value by specifying the delta.
Parameters:
color (str):
A hexadecimal color value to adjust.
hd (float):
% change in hue, _hue delta_.
sd (float):
% change in saturation, _saturation delta_.
vd (float):
% change in value, _value delta_.
Returns:
str:
The resulting hexadecimal color value
Source code in src/ttkbootstrap/style.py
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 | |