Style
Bases: Style
A singleton class for creating and managing the application theme and widget styles.
This class is meant to be a drop-in replacement for ttk.Style and
inherits all of it's methods and properties. However, in
ttkbootstrap, this class is implemented as a singleton. Subclassing
is not recommended and may have unintended consequences.
Examples:
```python
# instantiate the style with default theme
style = Style()
# instantiate the style with another theme
style = Style(theme='superhero')
# check all available themes
for theme in style.theme_names():
print(theme)
```
See the Python documentation on this class for more details.
Source code in src/ttkbootstrap/style.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 | |
colors
property
An object that contains the colors used for the current theme.
Returns:
Colors:
The colors object for the current theme.
dynamic_foreground
property
Returns True if dynamic foreground selection is enabled,
otherwise False.
__init__(theme=DEFAULT_THEME)
Parameters:
theme (str):
The name of the theme to use when styling the widget.
Source code in src/ttkbootstrap/style.py
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | |
get_instance()
staticmethod
Returns and instance of the style class
Source code in src/ttkbootstrap/style.py
820 821 822 823 | |
load_user_theme(theme)
Load a user theme definition
Source code in src/ttkbootstrap/style.py
903 904 905 | |
load_user_themes(file)
Load user themes saved in json format
Source code in src/ttkbootstrap/style.py
907 908 909 910 911 912 913 914 915 916 917 918 919 920 | |
register_theme(definition)
Register a theme definition for use by the Style
object. This makes the definition and name available at
run-time so that the assets and styles can be created when
needed.
Parameters:
definition (ThemeDefinition):
A `ThemeDefinition` object.
Source code in src/ttkbootstrap/style.py
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
style_exists_in_theme(ttkstyle)
Check if a style exists in the current theme.
Parameters:
ttkstyle (str):
The ttk style to check.
Returns:
bool:
`True` if the style exists, otherwise `False`.
Source code in src/ttkbootstrap/style.py
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 | |
theme_create(themename, parent=None, settings=None)
Create a new theme in the Tcl interpreter. If the parent is a registered ttkbootstrap theme, the new theme will be registered with a copied ThemeDefinition and builder. Duplicate registration is avoided.
Parameters:
themename (str):
The name of the new theme.
parent (str):
The name of the parent theme to inherit from.
settings (dict):
A dictionary of style settings (Tcl-style).
Source code in src/ttkbootstrap/style.py
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 | |
theme_names()
Return a list of all ttkbootstrap themes.
Returns:
list[str, ...]:
A list of theme names.
Source code in src/ttkbootstrap/style.py
651 652 653 654 655 656 657 658 659 | |
theme_use(themename=None)
Changes the theme used in rendering the application widgets.
If themename is None, returns the theme in use, otherwise, set
the current theme to themename, refreshes all widgets and emits
a <<ThemeChanged>> event.
Only use this method if you are changing the theme during runtime. Otherwise, pass the theme name into the Style constructor to instantiate the style with a theme.
Parameters:
themename (str):
The name of the theme to apply when creating new widgets
Returns:
Union[str, None]:
The name of the current theme if `themename` is None
otherwise, `None`.
Source code in src/ttkbootstrap/style.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 | |
use_dynamic_foreground(enable=True)
Enable or disable dynamic foreground color selection.
When enabled, the foreground color of widgets will be decided
between the fg and selectfg colors based on the
contrast ratio with the widget's background color.
At default, this is disabled.
Parameters:
enable (bool):
If `True`, dynamic foreground selection is enabled.
Otherwise, it is disabled.
Source code in src/ttkbootstrap/style.py
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 | |