ttkbootstrap documentation

ttkbootstrap is a collection of modern, flat themes inspired by Bootstrap for tkinter/ttk. There are more than a dozen built-in dark and light themes. Even better, you can create your own with TTK Creator!

_images/ttkbootstrap.gif

Installation

Installing ttkbootstrap is easy! There are a few options for installing.

PyPI

Installing from PyPI is the easiest and recommended method. It will contain the most up-to-date stable distribution:

python -m pip install ttkbootstrap==0.5.3

This also installs pillow as a required dependency if it is not already installed. This library is used to handle some of the image processing used in ttkbootstrap.

Note

If you are on Linux, you may not have a font with emojii support. To prevent the program from crashing, I recommend you also install the Symbola font.

sudo apt-get install fonts-symbola

Handbook

Overview

Why does this project exist?

The purpose of this project is create a set of beautifully designed and easy to apply styles for your tkinter applications. Ttk can be very time-consuming to style if you are just a casual user. This project takes the pain out of getting a modern look and feel so that you can focus on designing your application. This project was created to harness the power of ttk’s (and thus Python’s) existing built-in theme engine to create modern and professional-looking user interfaces which are inspired by, and in many cases, whole-sale rip-off’s of the themes found on Bootswatch. Even better, you have the abilty to create and use your own custom themes using TTK Creator.

A bootstrap approach to style

Many people are familiar with bootstrap for web developement. It comes pre-packaged with built-in css style classes that provide a professional and consistent api for quick development. I took a similar approach with this project by pre-defining styles for nearly all ttk widgets. This makes is very easy to apply the theme colors to various widgets by using style declarations. If you want a button in the secondary theme color, simply apply the secondary.TButton style to the button. Want a blue outlined button? Apply the info.Outline.TButton style to the button.

What about the old tkinter widgets?

Some of the ttk widgets utilize existing tkinter widgets. For example: there is a tkinter popdown list in the ttk.Combobox and a legacy tkinter widget inside the ttk.OptionMenu. To make sure these widgets didn’t stick out like a sore thumb, I created a StyleTK class to apply the same color and style to these legacy widgets. While these legacy widgets are not necessarily intended to be used (and will probably not look as nice as the ttk versions when they exist), they are available if needed, and shouldn’t look completely out-of-place in your ttkbootstrap themed application. Check out this example to see for yourself.

Tutorial

ttkbootstrap works by generating pre-defined themes at runtime which you can then apply and use as you would any built-in ttk theme such as clam, alt, classic, etc… You also have the ability to create a new theme using the ttkcreator application.

Simple usage

from ttkbootstrap import Style
from tkinter import ttk

style = Style()

window = style.master
ttk.Button(window, text="Submit", style='success.TButton').pack(side='left', padx=5, pady=10)
ttk.Button(window, text="Submit", style='success.Outline.TButton').pack(side='left', padx=5, pady=10)
window.mainloop()

This results in the window below:

_images/submit.png

If you do not create an instance of Tk(), the Style object automatically creates one. You can access this root window through the master property.

By default, the flatly theme will be applied to the application if you do not explicitly select one.

If you want to use a different theme, you can pass the style name as a keyword argument when you create the style object:

style = Style(theme='darkly')

Note

Check out the visual style guide for each widget. Here you will find an image for each available widget style, as well as information on how to apply and modify styles as needed for each widget.

Choose a theme

ttkbootstrap light and dark themes are generated at run-time. Generally, the ttkbootstrap.Style api is identical to the ttk.Style api. See the Python documentation on styling to learn more about this class.

To use a ttkbootstrap theme, create a ttkbootstrap.Style and pass in the name of the theme you want to use.

style = Style(theme='superhero')

If you want to load a theme from a specific file (for example, to release an application with a custom theme), you can use the user_themes argument:

style = Style(theme='custom_name', themes_file='C:/example/my_themes.json')

If for some reason you need to change the theme after the window has already been created, you will need to use the Style.theme_use method, which is what ttkbootstrap.Style does internally when instantiated.

To get a list of all available themes:

style.theme_names()

Currently, the available pre-defined themes include:

light

cosmo - flatly - journal - literal - lumen - minty - pulse - sandstone - united - yeti

dark

cyborg - darkly - solar - superhero

Use themed widgets

ttkbootstrap includes many pre-defined widget styles that you can apply with the style option on ttk widgets. The style pattern is Color.WidgetClass where the color is a prefix to the ttk widget class. Most widgets include a style pattern for each main theme color (primary, secondary, success, info, warning, danger).

For example, the ttk.Button has a widget class of TButton. The style patterns available on the button include:

  • primary.TButton

  • secondary.TButton

  • success.TButton

  • info.TButton

  • warning.TButton

  • danger.TButton

These style patterns produce the following buttons:

_images/color-options.png

Consider the following example, which also shows the Outline style that is available on buttons:

# solid button
ttk.Button(window, text="Submit", style='success.TButton').pack(side='left', padx=5, pady=10)

# outline button
ttk.Button(window, text="Submit", style='success.Outline.TButton').pack(side='left', padx=5, pady=10)
_images/submit.png

Note

While all widgets are themed, not all have themed color styles available, such as ttk.PanedWindow or the ttk.Scrollbar. Instead, these widgets are styled with a default theme color.

Modify a style

In a large application, you may need to customize widget styles. I’ve done this in several of gallery applications. To customize a style, you need to create a Style object first and then use the configure method using the pattern newName.oldName. In the File Backup Utility, I created a custom style for a frame that used the background color of the theme border.

For this example, let’s say that color is gray.

style = Style()
style.configure('custom.TFrame', background='gray')

This would create a frame style with the background color of gray. To apply this new style, I would create a frame and then use the style option to set the new style.

myframe = ttk.Frame(style='custom.TFrame')

There is a widget style class whose name is ‘.’ By configuring this widget style class, you will change some features’ default appearance for every widget that is not already configured by another style.

style.configure('.', font=('Helvetica', 10))

Use themed colors

ttkbootstrap has a Colors class that contains the theme colors as well as several helper methods for manipulating colors. This class is attached to the Style object at run-time for the selected theme, and so is available to use with Style.colors. The colors can be accessed via dot notation or get method:

# dot-notation
Colors.primary

# get method
Colors.get('primary')

This class is an iterator, so you can iterate over the main style color labels (primary, secondary, success, info, warning, danger):

for color_label in Colors:
    color = 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, including border, fg, bg, etc…

for color_label in Colors.label_iter():
    color = Colors.get(color_label)
    print(color_label, color)

Create a new theme

TTK Creator is a program that makes it really easy to create and use your own defined themes.

_images/ttkcreator.png
Starting the application

From the console, type:

python -m ttkcreator
Create and save your theme
  • Name your theme

  • Select a base theme to set the initial colors

  • Click the color palette to select a color, or input a hex or named color directly

  • Click Save on the menubar to save your theme

  • Click Reset to apply the base theme defaults and start from scratch

Theme names must be unique. If you choose a theme name that already exists, you will be prompted to choose another.

You can check your new theme by starting up the ttkbootstrap demo application, which will load all available themes. Then, select your new theme from the option menu.

python -m ttkbootstrap
Export or import your user defined themes
  • Click Export from the menubar to export user-defined themes into a .py file.

  • Click Import to import user-defined themes.

IMPORTANT!!! Importing user-defined themes will overwrite any user-defined themes that are currently saved in the library. Additionally, upgrading to a new version of ttkbootstrap will erase user-defined themes.

Themes

All of the following themes are available with ttkbootstrap and can be viewed live with the ttkbootstrap demo:

python -m ttkbootstrap

Light themes

an example image of theme cosmo

inspired by https://bootswatch.com/cosmo/

an example image of theme flatly

inspired by https://bootswatch.com/flatly/

an example image of theme journal

inspired by https://bootswatch.com/journal/

an example image of theme litera

inspired by https://bootswatch.com/litera/

an example image of theme lumen

inspired by https://bootswatch.com/lumen/

an example image of theme minty

inspired by https://bootswatch.com/minty/

an example image of theme pulse

inspired by https://bootswatch.com/pulse/

an example image of theme sandstone

inspired by https://bootswatch.com/sandstone/

an example image of theme united

inspired by https://bootswatch.com/united/

an example image of theme yeti

inspired by https://bootswatch.com/yeti/

an example image of theme yeti

inspired by https://bootswatch.com/morph/

Dark themes

an example image of theme darkly

inspired by https://bootswatch.com/darkly/

an example image of theme cyborg

inspired by https://bootswatch.com/cyborg/

an example image of theme superhero

inspired by https://bootswatch.com/superhero/

an example image of theme solar

inspired by https://bootswatch.com/solar/

How are themes created?

Imagine being able to take the parts from several existing cars to design the one that you really want… that’s basically how ttkbootstrap was created… I used the best parts of the existing themes to craft a brand new theme template.

The base of all widgets in the ttkbootstrap template is the clam theme. You may be wondering why the ttkbootstrap theme looks so different than the built-in clam theme… Each ttk widget is created from a collection of elements. These elements, when combined together, create what we see as a ttk widget. Aside from changing colors and state behavior, I constructed new widget layouts using the elements from various themes to give the desired look and feel. There is an old, but excellent reference to widget layouts here.

As an example: the ttk.Combobox widget contains a field element. In order to get the border effect I wanted, I constructed a new layout for the ttk.Combobox using the field from the ttk.Spinbox.

So, the ttkbootstrap.StylerTTK contains the style template for all ttkbootstrap themes. From there, a set of theme definitions (which includes color maps, default font, etc…) are extracted from a json file at runtime and loaded as a new theme by the ttkbootstrap.Style class.

{
  "name": "cosmo",
  "font": "Helvetica",
  "type": "light",
  "colors": {
                            "primary": "#2780e3",
                            "secondary": "#373a3c",
                            "success": "#3fb618",
                            "info": "#9954bb",
                            "warning": "#ff7518",
                            "danger": "#ff0039",
                            "light": "#f8f9fa",
                            "dark": "#373a3c",
                            "bg": "#ffffff",
                            "fg": "#373a3c",
                            "selectbg": "#373a3c",
                            "selectfg": "#ffffff",
                            "border": "#ced4da",
                            "inputfg": "#373a3c",
                            "inputbg": "#fdfdfe"
  }
}

This theme definition is read by the ttkbootstrap.Style class and converted into an actual theme by the ttkbootstrap.StylerTTK class at runtime. At that point, it is available to use like any other theme. The only information about a theme that is stored (built-in or user-defined) is the theme definition.

Legacy widget styles

While they are not the focus of this package, if you need to use legacy tkinter widgets, they should not look completely out-of-place. Below is an example of the widgets using the journal style. Legacy tkinter widgets will have the primary color applied. If you wish to use other theme colors on the widgets, you can override the styles as you would normally when using tkinter widgets. The theme colors are available in the Style.colors property.

an example image of legacy tkinter widgets styled with journal

Widget Styles

This is a style guide for using ttkbootstrap styles. This guide will show you how to apply visual styles to change the look and feel of the widget. If you want more information on how to use the widget and what options are available, consult the reference section on widgets.

Button

A ttk.Button widget displays a textual string, bitmap or image. If text is displayed, it must all be in a single font, but it can occupy multiple lines on the screen (if it contains newlines or if wrapping occurs because of the wraplength option) and one of the characters may optionally be underlined using the underline option. It can display itself in either of three different ways, according to the state option; it can be made to appear raised, sunken, or flat; and it can be made to flash. When a user invokes the button (by pressing mouse button 1 with the cursor over the button), then the command specified in the command option is invoked.

Note

This is a style guide for using ttkbootstrap styles. This guide will show you how to apply visual styles to change the look and feel of the widget. For more information on how to use the widget and what options are available, consult the reference section on widgets.

Overview

The ttk.Button includes the TButton, Outline.TButton, and Link.TButton style classes. The primary color is applied to all buttons by default. Other styles must be specified with the style option. These styles are further subclassed by each of the theme colors to produce the following color and style combinations:

_images/buttons.png

The Link.TButton has an info colored hover effect as well as a slight shiftrelief when the button is pressed.

How to use

The examples below demonstrate how to use a style when creating a widget. To learn more about how to use the widget in ttk, check out the References section for links to documentation and tutorials on this widget.

Create a default solid button

ttk.Button(parent, text='Submit')

Create a default outline button

ttk.Button(parent, text='Submit', style='Outline.TButton')

Create an ‘info’ solid button

ttk.Button(parent, text='Submit', style='info.TButton')

Create a ‘warning’ outline button

ttk.Button(parent, text="Submit", style='warning.Outline.TButton')
Style configuration

Use the following classes, states, and options when configuring or modifying a new ttk button style. See the python style documentation for more information on creating a style.

Create a new theme using TTK Creator if you want to change the default color scheme.

Class names
  • TButton

  • Outline.TButton

  • Link.TButton

Dynamic states
  • active

  • disabled

  • pressed

  • readonly

Style options
anchor

e, w, center

background

color

bordercolor

color

compound

top, bottom, left, right

darkcolor

color

embossed

amount

focuscolor

color

focusthickness

amount

foreground

color

font

font

highlightcolor

color

highlightthickness

amount

justify

left, right, center

lightcolor

color

padding

padding

relief

flat, groove, raised, ridge, solid, sunken

shiftrelief

amount

width

amount

Create a custom style

Change the font and font-size on all buttons

Style.configure('TButton', font=('Helvetica', 12))

Change the foreground color when the button is active

Style.map('TButton', foreground=[
    ('disabled', 'white'),
    ('active', 'yellow')])

Subclass an existing style to create a new one, using the pattern ‘newstyle.OldStyle’

Style.configure('custom.TButton', background='red', foreground='white', font=('Helvetica', 24))

Use a custom style

ttk.Button(parent, text='Submit', style='custom.TButton')
References

Checkbutton

A ttk.Checkbutton widget is used to show or change a setting. It has two states, selected and deselected. The state of the checkbutton may be linked to a tkinter variable.

Overview

The ttk.Checkbutton includes the TCheckbutton, Toolbutton, Outline.Toolbutton, Roundtoggle.Toolbutton, and Squaretoggle.Toolbutton style classes. The primary.TCheckbutton style is applied to all checkbuttons by default. Other styles must be specified with the style option. These primary styles are further subclassed by each of the theme colors to produce the following color and style combinations:

_images/checkbutton.png
_images/checkbutton_toolbutton.png _images/checkbutton_outline_toolbutton.png _images/roundtoggle.png _images/squaretoggle.png
How to use

The examples below demonstrate how to use a style to create a widget. To learn more about how to use the widget in ttk, check out the References section for links to documentation and tutorials on this widget.

Create a default checkbutton

ttk.Checkbutton(parent, text='include', value=1)

Create a default toolbutton

ttk.Checkbutton(parent, text='include', style='Toolbutton')

Create a default outline toolbutton

ttk.Checkbutton(parent, text='include', style='Outline.Toolbutton')

Create a default round toggle toolbutton

ttk.Checkbutton(parent, text='include', style='Roundtoggle.Toolbutton')

Create a default square toggle toolbutton

ttk.Checkbutton(parent, text='include', style='Squaretoggle.Toolbutton')

Create an ‘info’ checkbutton

ttk.Checkbutton(parent, text='include', style='info.TCheckbutton')

Create a ‘warning’ outline toolbutton

ttk.Checkbutton(parent, text="include", style='warning.Outline.Toolbutton')
Style configuration

Use the following classes, states, and options when configuring or modifying a new ttk checkbutton style. TTK Bootstrap uses an image layout for this widget, so not all of these options will be available… for example: indicatormargin. However, if you decide to create a new widget, these should be available, depending on the style you are using as a base. Some options are only available in certain styles. See the python style documentation for more information on creating a style.

Create a new theme using TTK Creator if you want to change the default color scheme.

Class names
  • TCheckbutton

  • Toolbutton

  • Outline.Toolbutton

  • Roundtoggle.Toolbutton

  • Squaretoggle.Toolbutton

Dynamic states
  • active

  • alternate

  • disabled

  • pressed

  • selected

  • readonly

Style options
background

color

compound

compound

foreground

foreground

focuscolor

color

focusthickness

amount

font

font

padding

padding

Create a custom style

Change the font and font-size on all checkbuttons

Style.configure('TCheckbutton', font=('Helvetica', 12))

Change the foreground color when the checkbutton is selected

Style.map('TCheckbutton', foreground=[
    ('disabled', 'white'),
    ('selected', 'yellow'),
    ('!selected', 'gray')])

Subclass an existing style to create a new one, using the pattern ‘newstyle.OldStyle’

Style.configure('custom.TCheckbutton', foreground='white', font=('Helvetica', 24))

Use a custom style

ttk.Checkbutton(parent, text='include', style='custom.TCheckbutton')
References

Calendar

The calendar module contains several classes and functions that enable the user to select a date.

Note

This is a style guide for using ttkbootstrap styles. This guide will show you how to apply visual styles to change the look and feel of the widget. For more information on how to use the widget and what options are available, consult the reference section on widgets.

Overview

The DateEntry and DateChooserPopup are the two classes that you will use along with the calendar.ask_date() helper function.

The DateEntry widget is a ttk.Entry widget combined with a ttk.Button widget that opens up a DateChooserPopup when pressed. It is recommended to not use the DateChooserPopup directly, unless you want to subclass it, but rather to use it via the calendar.ask_date() method, which opens up a DateChooserPopup and returns the selected value as a datetime object.

All of these objects have a style parameter that accept a TCalendar style. By default, the primary color is applied to the widget. However, the base style is further subclassed by each of the theme colors to produce the following color and style combinations for DateEntry and DateChooserPopup.

_images/date_entry.png

The styles above correspond to the same colored DateChooserPopup below:

_images/calendar_popup_primary.png _images/calendar_popup_secondary.png _images/calendar_popup_success.png _images/calendar_popup_info.png _images/calendar_popup_warning.png _images/calendar_popup_danger.png
How to use

The examples below demonstrate how to use a style when creating a calendar widget.

Create a default date entry

DateEntry(parent)

Create a success date entry

DateEntry(parent, style='success.TCalendar')

Create a button that calls the calendar popup by assigning a callback.

def callback():
    return ask_date()

btn = ttk.Button(parent, text='Get Date', command=callback)
Style configuration

Use the following classes, states, and options when configuring or modifying a new calendar style. Some options are only available in certain styles. See the python style documentation for more information on creating a style.

Create a new theme using TTK Creator if you want to change the default color scheme.

Class names
  • TCalendar

Dynamic states
  • active

  • alternate

  • disabled

  • pressed

  • selected

  • readonly

Style options
background

color

compound

compound

foreground

foreground

focuscolor

color

focusthickness

amount

font

font

padding

padding

Create a custom style

Change the font and font-size on all calendar buttons

Style.configure('TCalendar', font=('helvetica', 12))

Change the foreground color when the calendar date is selected

Style.map('TCalendar', foreground=[
    ('disabled', 'white'),
    ('selected', 'yellow'),
    ('!selected', 'gray')])

Subclass an existing style to create a new one, using the pattern ‘newstyle.OldStyle’

Style.configure('custom.TCalendar', foreground='tan', font=('Helvetica', 10))

Use a custom style

DateEntry(parent, style='custom.TCalendar')

Combobox

A ttk.Combobox widget is a combination of an Entry and a drop-down menu. In your application, you will see the usual text entry area, with a downward-pointing arrow. When the user clicks on the arrow, a drop-down menu appears. If the user clicks on one, that choice replaces the current contents of the entry. However, the user may still type text directly into the entry (when it has focus), or edit the current text.

Overview

The ttk.Combobox includes the TCombobox class. The primary color is applied by default. This style is further subclassed by each of the theme colors to produce the following color and style combinations.

_images/combobox_primary.png _images/combobox_secondary.png _images/combobox_success.png _images/combobox_info.png _images/combobox_warning.png _images/combobox_danger.png

As you can see, in a normal state, all styles look the same. What distinguishes them are the colors that are used for the active and focused states.

How to use

The examples below demonstrate how to use a style to create a widget. To learn more about how to use the widget in ttk, check out the References section for links to documentation and tutorials on this widget.

Create a default combobox

cb = ttk.Combobox(parent)

for option in ['option 1', 'option 2', 'option 3']:
    cb.insert('end', option)

Create an ‘info’ combobox

ttk.Combobox(parent, style='info.TCombobox')
Style configuration

Use the following classes, states, and options when configuring or modifying a new ttk combobox style. See the python style documentation for more information on creating a style.

Create a new theme using TTK Creator if you want to change the default color scheme.

Class names
  • TCombobox

Dynamic states
  • disabled

  • focus

  • pressed

  • readonly

Style options
anchor

e, w, center

arrowcolor

color

arrowsize

amount

background

color

bordercolor

color

borderwidth

amount

darkcolor

color

fieldbackground

color

foreground

color

font

font

lightcolor

color

padding

padding

relief

flat, groove, raised, ridge, solid, sunken

width

amount

Note

The popdown list cannot be configured using the Style class. Instead, you must use the tk option database.

  • tk.option_add('*TCombobox*Listbox.background', color)

  • tk.option_add('*TCombobox*Listbox.font', font)

  • tk.option_add('*TCombobox*Listbox.foreground', color)

  • tk.option_add('*TCombobox*Listbox.selectBackground', color)

  • tk.option_add('*TCombobox*Listbox.selectForeground', color)

Create a custom style

Change the font and font-size on all comboboxes

Style.configure('TCombobox', font=('Helvetica', 12))

Change the arrow color when in different states

Style.map('TCombobox', arrowcolor=[
    ('disabled', 'gray'),
    ('pressed !disabled', 'blue'),
    ('focus !disabled', 'green'),
    ('hover !disabled', 'yellow')])

Subclass an existing style to create a new one, using the pattern ‘newstyle.OldStyle’

Style.configure('custom.TCombobox', background='green', foreground='white', font=('Helvetica', 24))

Use a custom style

ttk.Combobox(parent, style='custom.TCombobox')
References

Entry

The ttk.Entry widget displays a one-line text string and allows that string to be edited by the user. The value of the string may be linked to a tkinter variable with the textvariable option. Entry widgets support horizontal scrolling with the standard xscrollcommand option and xview widget command.

Overview

The ttk.Entry includes the TEntry class. The primary color is applied by default. This style is further subclassed by each of the theme colors to produce the following color and style combinations.

_images/entry_primary.png _images/entry_secondary.png _images/entry_success.png _images/entry_info.png _images/entry_warning.png _images/entry_danger.png

As you can see, in a normal state, all styles look the same. What distinguishes them are the colors that are used for the active and focused states.

How to use

The examples below demonstrate how to use a style to create a widget. To learn more about how to use the widget in ttk, check out the References section for links to documentation and tutorials on this widget.

Create a default entry

entry = ttk.Entry(parent)

entry.insert('Hello world!')

Create an ‘info’ entry

ttk.Entry(parent, style='info.TEntry')
Style configuration

Use the following classes, states, and options when configuring or modifying a new ttk.Entry style. See the python style documentation for more information on creating a style.

Create a new theme using TTK Creator if you want to change the default color scheme.

Class names
  • TEntry

Dynamic states
  • disabled

  • focus

  • readonly

Style options
background

color

bordercolor

color

borderwidth

amount

darkcolor

color

fieldbackground

color

foreground

color

font

font

lightcolor

color

padding

padding

relief

flat, groove, raised, ridge, solid, sunken

selectbackground

color

selectborderwidth

amount

selectforeground

color

Create a custom style

Change the font and font-size on all entry widgets

Style.configure('TEntry', font=('Helvetica', 12))

Change the foreground color when in different states

Style.map('TEntry', foreground=[
    ('disabled', 'gray'),
    ('focus !disabled', 'green'),
    ('hover !disabled', 'yellow')])

Subclass an existing style to create a new one, using the pattern ‘newstyle.OldStyle’

Style.configure('custom.TEntry', background='green', foreground='white', font=('Helvetica', 24))

Use a custom style

ttk.Entry(parent, style='custom.TEntry')
References

Floodgauge

A Floodgauge widget is a custom ttkbootstrap widget that shows the status of a long-running operation with an optional text indicator. Similar to the ttk.Progressbar, this widget can operate in two modes: determinate mode shows the amount completed relative to the total amount of work to be done, and indeterminate mode provides an animated display to let the user know that something is happening.

Note

This is a style guide for using ttkbootstrap styles. This guide will show you how to apply visual styles to change the look and feel of the widget. For more information on how to use the widget and what options are available, consult the reference section on widgets.

Overview

The Floodgauge includes the Horizontal.TFloodgauge and Vertical.TFloodgauge styles. These styles are further subclassed by each of the theme colors to produce the following color and style combinations (the primary color is the default for all floodgauge widgets:

_images/floodgauge_horizontal.png _images/floodgauge_vertical.png
How to use

The examples below demonstrate how to use a style to create a widget. To learn more about how to use the widget in ttk, check out the references section.

Create a default horizontal floodgauge

Floodgauge(parent, value=75)

Create a default vertical floodgauge

Floodgauge(parent, value=75, orient='vertical')

Create a success colored horizontal floodgauge

Floodgauge(parent, value=75, style='success.Horizontal.TFloodgauge')

Create an info colored vertical floodgauge

Floodgauge(parent, value=75, style='info.Vertical.TFloodgauge', orient='vertical')
Configuration

Use the following classes, states, and options when configuring or modifying a new ttk floodgauge style. See the python style documentation for more information on creating a style.

Create a new theme using TTK Creator if you want to change the default color scheme.

Class names
  • Horizontal.TFloodgauge

  • Vertical.TFloodgauge

Style options
background

color

barsize

amount

bordercolor

color

borderwidth

amount

darkcolor

color

lightcolor

color

pbarrelief

flat, groove, raised, ridge, solid, sunken

thickness

amount

troughcolor

color

troughrelief

flat, groove, raised, ridge, solid, sunken

Create a custom style

Change the thickness and relief of all floodgauges

Style.configure('TFloodgauge', thickness=20, pbarrelief='flat')

Subclass an existing style to create a new one, using the pattern ‘newstyle.OldStyle’

Style.configure('custom.Horizontal.TFloodgauge', background='green', troughcolor='gray')

Use a custom style

Floodgauge(parent, value=25, orient='horizontal', style='custom.Horizontal.TFloodgauge')

Frame

A ttk.Frame widget is a container, used to group other widgets together.

Overview

The ttk.Frame includes the TFrame class. This class is further subclassed by each of the theme colors to produce the following color and style combinations. The TFrame style is applied to all frame widgets by default and shares the same color as the theme background.

_images/frame.png
How to use

The examples below demonstrate how to use a style to create a widget. To learn more about how to use the widget in ttk, check out the References section for links to documentation and tutorials on this widget.

Create a default frame

ttk.Frame(parent)

Create an ‘info’ frame

ttk.Frame(parent, style='info.TFrame')
Style configuration

Use the following classes, states, and options when configuring or modifying a new ttk button style. See the python style documentation for more information on creating a style.

Create a new theme using TTK Creator if you want to change the default color scheme.

Class names
  • TFrame

Dynamic states
  • disabled

  • focus

  • pressed

  • readonly

Style options
background

color

relief

flat, groove, raised, ridge, solid, sunken

Create a custom style

Subclass an existing style to create a new one, using the pattern ‘newstyle.OldStyle’

Style.configure('custom.TFrame', background='green', relief='sunken')

Use a custom style

ttk.Frame(parent, style='custom.TFrame')
Tips & tricks

If you use a themed Frame widget, then you will likely want to use a Label widget with an Inverse.TLabel style. This will create the effect that is presented in the Overview, with the the label background matching the background color of its parent.

frm = ttk.Frame(parent, style='danger.TFrame')
lbl = ttk.Label(f, text='Hello world!', style='danger.Inverse.TLabel')
References

Label

A ttk.Label widget displays a textual label and/or image. The label may be linked to a tkinter variable to automatically change the displayed text.

Overview

The ttk.Label includes the TLabel and Inverse.TLabel style classes. The TLabel style is applied to all labels by default and uses the theme’s inputfg color for the foreground and the background color for the background. Other styles must be specified with the style option. These two primary styles are further subclassed by each of the theme colors to produce the following color and style combinations:

_images/label.png

The theme colors can be inverted by using the Inverse.TLabel style, which causes the background and foreground colors to reverse.

How to use

The examples below demonstrate how to use a style to create a widget. To learn more about how to use the widget in ttk, check out the References section for links to documentation and tutorials on this widget.

Create a default label

ttk.Label(parent, text='python is great')

Create a default inverse label

ttk.Label(parent, text='python is great', style='Inverse.TLabel')

Create an ‘info’ label

ttk.Label(parent, text='python is great', style='info.TLabel')

Create a ‘warning’ inverse label

ttk.Label(parent, text="python is great", style='warning.Inverse.TLabel')
Style configuration

Use the following classes, states, and options when configuring or modifying a new ttk label style. See the python style documentation for more information on creating a style.

Create a new theme using TTK Creator if you want to change the default color scheme.

Class names
  • TLabel

  • Inverse.TLabel

Dynamic states
  • disabled

  • readonly

Style options
anchor

e, w, center

background

color

bordercolor

color

compound

top, bottom, left, right

darkcolor

color

embossed

amount

foreground

color

font

font

justify

left, right, center

lightcolor

color

padding

padding

relief

flat, groove, raised, ridge, solid, sunken

width

amount

Create a custom style

Change the font and font-size on all labels

Style.configure('TLabel', font=('Helvetica', 12))

Subclass an existing style to create a new one, using the pattern ‘newstyle.OldStyle’

Style.configure('custom.TLabel', background='red', foreground='white', font=('Helvetica', 24))

Use a custom style

ttk.Label(parent, text='what a great label', style='custom.TLabel')
Tips & tricks

You can apply a TButton style to a label to inherit the colors and hover effects of the button.

References

Labelframe

A ttk.Labelframe widget is a container used to group other widgets together. It has an optional label, which may be a plain text string or another widget.

Overview

The ttk.Labelframe includes the TLabelframe style class. The TLabelframe style is applied to all Labelframes by default and uses the theme border color for the frame and background color for the background. Other styles must be specified with the style option. This style is further subclassed by each of the theme colors to produce the following color and style combinations:

_images/labelframe.png
How to use

The examples below demonstrate how to use a style to create a widget. To learn more about how to use the widget in ttk, check out the References section for links to documentation and tutorials on this widget.

Create a default labelframe

ttk.Labelframe(parent, text='My widgets')

Create an ‘info’ labelframe

ttk.Labelframe(parent, text='My widgets', style='info.TLabelframe')
Style configuration

Use the following classes, states, and options when configuring or modifying a new ttk labelframe style. See the python style documentation for more information on creating a style.

Create a new theme using TTK Creator if you want to change the default color scheme.

Class names
  • TLabelframe

Dynamic states
  • disabled

  • readonly

Style options
anchor

e, w, center

background

color

bordercolor

color

borderwidth

amount

darkcolor

color

labelmargins

amount

labeloutside

boolean

lightcolor

color

padding

padding

relief

flat, groove, raised, ridge, solid, sunken

width

amount

TLabelframe.Label styling options include:

background

color

darkcolor

color

font

font

foreground

color

lightcolor

color

References

Meter

The Meter is a custom ttkbootstrap widget that can be used to show progress of long-running operations or the amount of work completed. It can also be used as a Dial when interactive mode is set to True.

Note

This is a style guide for using ttkbootstrap styles. This guide will show you how to apply visual styles to change the look and feel of the widget. For more information on how to use the widget and what options are available, consult the reference section on widgets.

Overview

This widget is very flexible. The metertype parameter has two stock settings: full and semi, which shows a full circle and a semi-circle respectively. Customize the arc of the circle with the arcrange and arcoffset parameters. This moves the starting position of the arc and can also be used to make the arc longer or shorter.

The meter color is set with meterstyle and uses the TMeter style class. This also colors the center text. There is an optional supplementary label below the center text that can be styled with the labelstyle parameter, which excepts a TLabel style class. This setting also formats the text added with textappend and textprepend.

The primary.TMeter style is applied by default. The base style is further subclassed by each of the theme colors to produce the following color and style combinations:

_images/meter.png

The examples below demonstrate how flexible this widget can be. You can see the code for these in the Cookbook.

_images/meter_variations.png
How to use

The examples below demonstrate how to use a style when creating a meter widget.

Create a default meter

Meter(parent, amountused=25, labeltext='miles per hour')

Create a danger meter

Meter(parent, amountused=25, labeltext='miles per hour', meterstyle='danger.TLabel')

Create an info meter with an success label

Meter(parent, amountused=25, labeltext='miles per hour', meterstyle='info.TLabel', labelstyle='success.TLabel')

Notebook

A ttk.Notebook widget manages a collection of windows and displays a single one at a time. Each content window is associated with a tab, which the user may select to change the currently-displayed window.

Overview

The ttk.Notebook includes the TNotebook style class. Presently, this style contains default settings for light and dark themes, but no other styles are included. This may change in the future. See the Create a custom style section to learn how to customize and create a notebook style.

_images/notebook.png
How to use

The examples below demonstrate how to use a style to create a widget. To learn more about how to use the widget in ttk, check out the References section for links to documentation and tutorials on this widget.

Create and use a notebook

# create a new notebook
nb = ttk.Notebook(parent)

# create a new frame
frame = ttk.Frame(nb)

# set the frame as a tab in the notebook
nb.add(frame, text='Tab 1')
Configuration

Use the following classes, states, and options when configuring or modifying a new ttk notebook style. See the python style documentation for more information on creating a style.

Create a new theme using TTK Creator if you want to change the default color scheme.

Class names
  • TNotebook

  • TNotebook.Tab

Dynamic states
  • active

  • disabled

  • selected

Style options
background

color

bordercolor

color

darkcolor

color

foreground

color

lightcolor

color:

padding

padding

tabmargins

padding

tabposition

n, s, e, w, ne, en, nw, wn, se, es, sw, ws

TNotebook.Tab styling options include:

background

color

bordercolor

color

compound

left, right, top, button

expand

padding

font

font

foreground

color

padding

padding

Create a custom style

Subclass an existing style to create a new one, using the pattern ‘newstyle.OldStyle’. In this example, the tab position is set to the southwest corner of the notebook… by default it is on the northwest corner.

# set the tabs on the sw corner of the notebook
Style.configure('custom.TNotebook', tabposition='sw')

Use a custom style

nb = ttk.Notebook(parent, style='custom.TNotebook')
References

PanedWindow

A ttk.PanedWindow widget displays a number of subwindows, stacked either vertically or horizontally. The user may adjust the relative sizes of the subwindows by dragging the sash between panes.

Overview

The ttk.PanedWindow includes the TPanedwindow style class. Presently, this style contains default settings for light and dark themes, but no other styles are included. This may change in the future. See the Create a custom style section to learn how to customize and create a paned window style.

How to use

The examples below demonstrate how to use a style to create a widget. To learn more about how to use the widget in ttk, check out the References section for links to documentation and tutorials on this widget.

Create and use a Paned Window

# create a new paned window
pw = ttk.PanedWindow(parent, orient='horizontal')

# add something on the left side
left_frame = ttk.Frame(pw)
left_frame.pack(side='left', fill='both')

# add something on the right side
right_frame = ttk.Frame(pw)
right_frame.pack(side='left', fill='both')

# add the frames to the paned window; a sash will appear between each frame (see image above)
pw.add(left_frame)
pw.add(right_frame)
Configuration

Use the following classes, states, and options when configuring or modifying a new ttk paned window style. See the python style documentation for more information on creating a style.

Create a new theme using TTK Creator if you want to change the default color scheme.

Class names
  • TPanedwindow

  • Sash

Style options

TPanedwindow styling options:

background

color

Sash styling options:

background

color

bordercolor

color

gripcount

count

handlepad

amount

handlesize

amount

lightcolor

color

sashpad

amount

sashrelief

flat, groove, raised, ridge, solid, sunken

sashthickness

amount

Create a custom style

Change the relief on all paned window sashes, and change the gripcount

Style.configure('Sash', relief='flat', gripcount=15)

Subclass an existing style to create a new one, using the pattern ‘newstyle.OldStyle’

Style.configure('custom.TPanedwindow', background='red')

Use a custom style

ttk.PanedWindow(parent, style='custom.TPanedwindow')
References

Progressbar

A ttk.Progressbar widget shows the status of a long-running operation. They can operate in two modes: determinate mode shows the amount completed relative to the total amount of work to be done, and indeterminate mode provides an animated display to let the user know that something is happening.

Overview

The ttk.Progressbar includes the Horizontal.TProgressbar, Vertical.TProgressbar, and Striped.Horizontal.TProgressbar styles. These styles are further subclassed by each of the theme colors to produce the following color and style combinations (the primary color is the default for all progress bars:

_images/progressbar_horizontal.png _images/progressbar_horizontal_striped.png _images/progressbar_vertical.png
How to use

The examples below demonstrate how to use a style to create a widget. To learn more about how to use the widget in ttk, check out the References section for links to documentation and tutorials on this widget.

Create a default horizontal progressbar

ttk.Progressbar(parent, value=75)

Create a default vertical progressbar

ttk.Progressbar(parent, value=75, orient='vertical')

Create a default horizontal striped progressbar

ttk.Progressbar(parent, value=75, style='Striped.Horizontal.TProgressbar')

Create a success horizontal striped progressbar

ttk.Progressbar(parent, value=75, style='success.Striped.Horizontal.TProgressbar')
Configuration

Use the following classes, states, and options when configuring or modifying a new ttk progressbar style. The Striped.Horizontal.TProgressbar is an image-based layout, so the styling options will be limited to those which affect the trough. The regular progressbar styles can be configured with all available options. See the python style documentation for more information on creating a style.

Create a new theme using TTK Creator if you want to change the default color scheme.

Class names
  • Horizontal.TProgressbar

  • Vertical.TProgressbar

  • Striped.Horizontal.TProgressbar

Style options
background

color

barsize

amount

bordercolor

color

borderwidth

amount

darkcolor

color

lightcolor

color

pbarrelief

flat, groove, raised, ridge, solid, sunken

thickness

amount

troughcolor

color

troughrelief

flat, groove, raised, ridge, solid, sunken

Create a custom style

Change the thickness and relief of all progressbars

Style.configure('TProgressbar', thickness=20, pbarrelief='flat')

Subclass an existing style to create a new one, using the pattern ‘newstyle.OldStyle’

Style.configure('custom.Horizontal.TProgressbar', background='green', troughcolor='gray')

Use a custom style

ttk.Progressbar(parent, value=25, orient='horizontal', style='custom.Horizontal.TProgressbar')
References

Radiobutton

A ttk.Radiobutton widget is used in groups to show or change a set of mutually-exclusive options. Radiobuttons are linked to a tkinter variable, and have an associated value; when a radiobutton is clicked, it sets the variable to its associated value.

Overview

The ttk.Radiobutton includes the TRadiobutton, ToolButton, and Outline.Toolbutton styles. These styles are further subclassed by each of the theme colors to produce the following color and style combinations:

_images/radiobutton.png
_images/radiobutton_toolbutton.png _images/radiobutton_outline_toolbutton.png
How to use

The examples below demonstrate how to use a style to create a widget. To learn more about how to use the widget in ttk, check out the References section for links to documentation and tutorials on this widget.

Create a default radiobutton

ttk.Radiobutton(parent, text='option 1')

Create a default toolbutton

ttk.Radiobutton(parent, text='option 2', style='Toolbutton')

Create a default outline toolbutton

ttk.Radiobutton(parent, text='option 3', style='Outline.Toolbutton')

Create an ‘info’ radiobutton

ttk.Radiobutton(parent, text='option 4', style='info.TRadiobutton')

Create a ‘warning’ outline toolbutton

ttk.Radiobutton(parent, text="option 5", style='warning.Outline.Toolbutton')
Configuration

Use the following classes, states, and options when configuring or modifying a new ttk radiobutton style. TTK Bootstrap uses an image layout for the TRadiobutton style on this widget, so not all of these options will be available… for example: indicatormargin. However, if you decide to create a new widget, these should be available, depending on the style you are using as a base. Some options are only available in certain styles. See the python style documentation for more information on creating a style.

Create a new theme using TTK Creator if you want to change the default color scheme.

Class names
  • TRadiobutton

  • Toolbutton

  • Outline.Toolbutton

Dynamic states
  • active

  • alternate

  • disabled

  • pressed

  • selected

  • readonly

Style options
background

color

compound

compound

foreground

foreground

focuscolor

color

focusthickness

amount

font

font

padding

padding

Create a custom style

Change the font and font-size on all radiobuttons

Style.configure('TRadiobutton', font=('Helvetica', 12))

Change the foreground color when the radiobutton is selected

Style.map('TRadiobutton', foreground=[
    ('disabled', 'white'),
    ('selected', 'yellow'),
    ('!selected', 'gray')])

Subclass an existing style to create a new one, using the pattern ‘newstyle.OldStyle’

Style.configure('custom.TRadiobutton', foreground='white', font=('Helvetica', 24))

Use a custom style

ttk.Radiobutton(parent, text='option 1', style='custom.TRadiobutton')
References

Slider

A ttk.Scale widget is typically used to control the numeric value of a linked variable that varies uniformly over some range. A scale displays a slider that can be moved along over a trough, with the relative position of the slider over the trough indicating the value of the variable.

Overview

The ttk.Scale includes the Horizontal.TScale and Vertical.TScale style classes. These styles are further subclassed by each of the theme colors to produce the following color and style combinations:

_images/scale_horizontal.png
_images/scale_vertical.png
How to use

The examples below demonstrate how to use a style to create a widget. To learn more about how to use the widget in ttk, check out the References section for links to documentation and tutorials on this widget.

Create a default horizontal scale

ttk.Scale(parent, from_=0, to=100, value=75)

Create a default vertical scale

ttk.Scale(parent, from_=0, to=100, value=75, orient='vertical')
Configuration

Use the following classes, states, and options when configuring or modifying a new ttk progressbar style. TTK Bootstrap uses an image layout for this widget, so styling options will be limited, and not all options below will be available for ttk bootstrap themes. See the python style documentation for more information on creating a style.

Create a new theme using TTK Creator if you want to change the default color scheme.

Class names
  • Horizontal.TScale

  • Vertical.TScale

Dynamic states
  • Active

Style options
background

color

borderwidth

amount

darkcolor

color

groovewidth

amount

lightcolor

color

sliderwidth

amount

troughcolor

color

relief

flat, groove, raised, ridge, solid, sunken

References

Scrollbar

ttk.Scrollbar widgets are typically linked to an associated window that displays a document of some sort, such as a file being edited or a drawing. A scrollbar displays a thumb in the middle portion of the scrollbar, whose position and size provides information about the portion of the document visible in the associated window. The thumb may be dragged by the user to control the visible region. Depending on the theme, two or more arrow buttons may also be present; these are used to scroll the visible region in discrete units.

Overview

The ttk.Scrollbar includes the Horizontal.TScrollbar and Vertical.TScrollbar style classes. These styles are applied by default to horizontal and vertical orientations. So there is no need to specify the styles unless you decide to create a new custom style.

_images/scrollbar_horizontal.png
_images/scrollbar_vertical.png
How to use

The examples below demonstrate how to use a style to create a widget. To learn more about how to use the widget in ttk, check out the References section for links to documentation and tutorials on this widget.

Create a default horizontal scrollbar

ttk.Scrollbar(parent, orient='horizontal')

Create a default vertical scrollbar

ttk.Scrollbar(parent, orient='vertical')
Configuration

Use the following classes, states, and options when configuring or modifying a new ttk scrollbar style. TTK Bootstrap uses an image layout for parts of this widget (the arrows), so styling options will not affect these elements. However, if you choose to create your own scrollbar layout and style, you may use whatever style options are available for your custom style. See the python style documentation for more information on creating a style.

Create a new theme using TTK Creator if you want to change the default color scheme.

Class names
  • Horizontal.TScrollbar

  • Vertical.TScrollbar

Dynamic states
  • active

  • disabled

Style options
arrowcolor

color

arrowsize

amount

background

color

bordercolor

color

gripcount

amount

groovewidth

amount

relief

flat, groove, raised, ridge, solid, sunken

troughborderwidth

amount

troughcolor

color

troughrelief

flat, groove, raised, ridge, solid, sunken

width

amount

Create a custom style

Change the thickness and background of all scrollbars

Style.configure('TScrollbar', width=30, background='black')

Subclass an existing style to create a new one, using the pattern ‘newstyle.OldStyle’

Style.configure('custom.Horizontal.TScrollbar', background='black', troughcolor='white', arrowcolor='white')

Use a custom style

ttk.Scrollbar(parent, orient='horizontal', style='custom.Horizontal.TScrollbar')
References

Separator

A ttk.Separator widget displays a horizontal or vertical separator bar.

Overview

The ttk.Separator includes the Horizontal.TSeparator and Vertical.TSeparator style classes. These styles are applied by default to horizontal and vertical orientations. These styles are further subclassed by each of the theme colors to produce the following color and style combinations:

_images/separator_horizontal.png
_images/separator_vertical.png
How to use

The examples below demonstrate how to use a style to create a widget. To learn more about how to use the widget in ttk, check out the References section for links to documentation and tutorials on this widget.

Create a default horizontal separator

ttk.Separator(parent, orient='horizontal')

Create a default vertical separator

ttk.Separator(parent, orient='vertical')

Create an info vertical separator

ttk.Separator(parent, orient='vertical', style='info.Vertical.TSeparator')
Configuration

Use the following classes, states, and options when configuring or modifying a new ttk separator style. TTK Bootstrap uses an image layout for this widget, so it is not possible to create a custom style without building a new layout. However, if you decide to build your own layout, you are free to use the styling options below. See the python style documentation for more information on creating a style.

Create a new theme using TTK Creator if you want to change the default color scheme.

Class names
  • Horizontal.TSeparator

  • Vertical.TSeparator

Style options
background

color

References

Sizegrip

A ttk.Sizegrip widget (also known as a grow box) allows the user to resize the containing toplevel window by pressing and dragging the grip.

Overview

The ttk.Sizegrip includes the TSizegrip style class. By default, the color of the sizegrip is the border color for light themes and the inputfg color for dark themes. This is further subclassed by each of the theme colors to produce the following color and style combinations:

_images/sizegrip.png _images/sizegrip_primary.png _images/sizegrip_secondary.png _images/sizegrip_success.png _images/sizegrip_info.png _images/sizegrip_warning.png _images/sizegrip_danger.png
How to use

The examples below demonstrate how to use a style to create a widget. To learn more about how to use the widget in ttk, check out the References section for links to documentation and tutorials on this widget.

Create a default sizegrip

ttk.Sizegrip(parent)

Create a success sizegrip

ttk.Sizegrip(parent, style='success.TSizegrip')
Configuration

Use the following classes, states, and options when configuring or modifying a new ttk sizegrip style. TTK Bootstrap uses an image layout for this widget, so styling options will not be available for TTK Bootstrap themes. See the python style documentation for more information on creating a style.

Create a new theme using TTK Creator if you want to change the default color scheme.

Class names
  • TSizegrip

Style options
  • background color

References

Spinbox

A ttk.Spinbox widget is a ttk.Entry widget with built-in up and down buttons that are used to either modify a numeric value or to select among a set of values. The widget implements all the features of the ttk.Entry widget including support of the textvariable option to link the value displayed by the widget to a tkinter variable.

Overview

The ttk.Spinbox includes the TSpinbox class. The primary color is applied to this widget by default. This style is further subclassed by each of the theme colors to produce the following color and style combinations.

_images/spinbox_primary.png
_images/spinbox_secondary.png
_images/spinbox_success.png
_images/spinbox_info.png
_images/spinbox_warning.png
_images/spinbox_danger.png

As you can see, in a normal state, all styles look the same. What distinguishes them are the colors that are used for the active and focused states.

How to use

The examples below demonstrate how to use a style to create a widget. To learn more about how to use the widget in ttk, check out the References section for links to documentation and tutorials on this widget.

Create a default spinbox

cb = ttk.Spinbox(parent, from_=1, to=100)

Create an ‘info’ spinbox

ttk.Spinbox(parent, from_=1, to=100, style='info.TSpinbox')
Configuration

Use the following classes, states, and options when configuring or modifying a new ttk spinbox style. Or, See the python style documentation for more information on creating a style.

create a new theme using TTK Creator if you want to change the default color scheme.

Class names
  • TSpinbox

Dynamic states
  • active

  • disabled

  • focus

  • readonly

Style options
arrowcolor

color

arrowsize

amount

background

color (same as fieldbackground)

bordercolor

color

darkcolor

color

fieldbackground

color

foreground

color

insertcolor

color

insertwidth

amount

lightcolor

color

padding

padding

selectbackground

color

selectforeground

color

Create a custom style

Change the arrow color when in different states

Style.map('TSpinbox', arrowcolor=[
    ('disabled', 'gray'),
    ('pressed !disabled', 'blue'),
    ('focus !disabled', 'green'),
    ('hover !disabled', 'yellow')])

Subclass an existing style to create a new one, using the pattern ‘newstyle.OldStyle’

Style.configure('custom.TSpinbox', background='green', foreground='white', font=('Helvetica', 24))

Use a custom style

ttk.Spinbox(parent, style='custom.TSpinbox')
References

Treeview

The ttk.Treeview widget displays a hierarchical collection of items. Each item has a textual label, an optional image, and an optional list of data values. The data values are displayed in successive columns after the tree label.

The order in which data values are displayed may be controlled by setting the displaycolumns widget option. The tree widget can also display column headings. Columns may be accessed by number or by symbolic names listed in the columns widget option.

Each item is identified by a unique name. The widget will generate item IDs if they are not supplied by the caller. There is a distinguished root item, named {}. The root item itself is not displayed; its children appear at the top level of the hierarchy.

Each item also has a list of tags, which can be used to associate event bindings with individual items and control the appearance of the item.

Treeview widgets support horizontal and vertical scrolling with the standard [xy]scrollcommand options and [xy]view widget commands.

Overview

The ttk.Treeview includes the Treeview class. The primary color is applied to this widget by default. This style is further subclassed by each of the theme colors to produce the following color and style combinations.

_images/treeview_primary.png _images/treeview_secondary.png _images/treeview_success.png _images/treeview_info.png _images/treeview_warning.png _images/treeview_danger.png
How to use

The examples below demonstrate how to use a style to create a widget. To learn more about how to use the widget in ttk, check out the References section for links to documentation and tutorials on this widget.

Create a default treeview

cb = ttk.Treeview(parent, columns=[1, 2, 3], show='headings')

Create an ‘info’ treeview

ttk.Treeview(parent, columns=[1, 2, 3], show='headings', style='info.Treeview')
Configuration

Use the following classes, states, and options when configuring or modifying a new ttk separator style. See the python style documentation for more information on creating a style.

Create a new theme using TTK Creator if you want to change the default color scheme.

Class names
  • Treeview

  • Heading

  • Item

  • Cell

Dynamic states
  • disabled

  • selected

Style options

Treeview styling options include:

background

color

fieldbackground

color

font

font

foreground

color

rowheight

amount

Heading styling options include:

background

color

font

font

relief

relief

Item styling options include:

foreground

color

indicatormargins

padding

indicatorsize

amount

padding

padding

Cell styling options include:

padding

padding

References

Cookbook

A collection of examples that demonstrate how to use ttk and ttkbootstrap widgets in interesting and useful ways.

Dials & Meters

This example demonstrates the versitility of the Meter widget. All of the example below were created using the same class. All of the examples below include a supplemental label using the labeltext parameter, and all but the first example use the textappend parameter to add the ‘gb’, ‘%’, and degrees symbol. Finally, all of the examples use the parameter interactive=True which turns the meter into a dial that can be manipulated directly with a mouse-click or drag. The theme used for the examples below is cosmo.

top-left

the metertype is semi which gives the meter a semi-circle arc. The meterstyle is primary.TLabel.

top-right

the stripethickness is 10 pixels to give it a segmented appearance. The meterstyle is info.TLabel.

bottom-left

the stripethickness is 2 pixels to give it a very thin segmented appearance. The meterstyle is success.TLabel.

bottom-right

this example has a custom arc, with the arcrange at 180, the arcoffset at -180 and the wedgethickness at 5 pixels in order to create a wedge style indicator that rests at the meter value. The meterstyle is danger.TLabel.

_images/dials_and_meters.png
"""
    Author: Israel Dryer
    Modified: 2021-05-09
"""

from ttkbootstrap import Style
from ttkbootstrap.widgets import Meter

style = Style('cosmo')
root = style.master
root.title('ttkbootstrap')

m1 = Meter(metersize=180, padding=20, amountused=25, metertype='semi', labeltext='miles per hour', interactive=True)
m1.grid(row=0, column=0)

m2 = Meter(metersize=180, padding=20, amountused=1800, amounttotal=2600, labeltext='storage used', textappend='gb',
           meterstyle='info.TMeter', stripethickness=10, interactive=True)
m2.grid(row=0, column=1)

m3 = Meter(metersize=180, padding=20, stripethickness=2, amountused=40, labeltext='project capacity', textappend='%',
           meterstyle='success.TMeter', interactive=True)
m3.grid(row=1, column=0)

m4 = Meter(metersize=180, padding=20, amounttotal=280, arcrange=180, arcoffset=-180, amountused=75, textappend='°',
           labeltext='heat temperature', wedgesize=5, meterstyle='danger.TMeter', interactive=True)
m4.grid(row=1, column=1)

root.mainloop()

Reference

Module

Colors

class ttkbootstrap.Colors(primary, secondary, success, info, warning, danger, bg, fg, selectbg, selectfg, border, inputfg, inputbg, light='#ddd', dark='#333')[source]

Bases: object

A class that contains the theme colors as well as several helper methods for manipulating colors.

This class is attached to the Style object at run-time for the selected theme, and so is available to use with Style.colors. The colors can be accessed via dot notation or get method:

# dot-notation
Colors.primary

# get method
Colors.get('primary')

This class is an iterator, so you can iterate over the main style color labels (primary, secondary, success, info, warning, danger):

for color_label in Colors:
    color = 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, including border, fg, bg, etc…

for color_label in Colors.label_iter():
    color = Colors.get(color_label)
    print(color_label, color)
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.

  • 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: ie. Entry, Combobox, etc…

  • inputbg (str) – the text background color for input widgets.

  • light (str) – a light color

  • dark (str) – a dark color

get(color_label)[source]

Lookup a color property

Parameters

color_label (str) – a color label corresponding to a class propery (primary, secondary, success, etc…)

Returns

a hexadecimal color value.

Return type

str

static hex_to_rgb(color)[source]

Convert hexadecimal color to rgb color value

Parameters

color (str) – param str color: hexadecimal color value

Returns

rgb color value.

Return type

tuple[int, int, int]

static label_iter()[source]

Iterate over all color label properties in the Color class

Returns

an iterator representing the name of the color properties

Return type

iter

static rgb_to_hex(r, g, b)[source]

Convert rgb to hexadecimal color value

Parameters
  • r (int) – red

  • g (int) – green

  • b (int) – blue

Returns

a hexadecimal colorl value

Return type

str

set(color_label, color_value)[source]

Set a color property

Parameters
  • color_label (str) – the name of the color to be set (key)

  • color_value (str) – a hexadecimal color value

Example

static update_hsv(color, hd=0, sd=0, vd=0)[source]

Modify the hue, saturation, and/or value of a given hex color value.

Parameters
  • color (str) – the hexadecimal color value that is the target of hsv changes.

  • hd (float) – % change in hue

  • sd (float) – % change in saturation

  • vd (float) – % change in value

Returns

a new hexadecimal color value that results from the hsv arguments passed into the function

Return type

str

Style

class ttkbootstrap.Style(theme='flatly', themes_file=None, *args, **kwargs)[source]

Bases: tkinter.ttk.Style

A class for setting the application style.

Sets the theme of the tkinter.Tk instance and supports all ttkbootstrap and ttk themes provided. This class is meant to be a drop-in replacement for ttk.Style and inherits all of it’s methods and properties. Creating a Style object will instantiate the tkinter.Tk instance in the Style.master property, and so it is not necessary to explicitly create an instance of tkinter.Tk. For more details on the ttk.Style class, see the python documentation.

# instantiate the style with default theme *flatly*
style = Style()

# instantiate the style with another theme
style = Style(theme='superhero')

# instantiate the style with a theme from a specific themes file
style = Style(theme='custom_name', themes_file='C:/example/my_themes.json')

# available themes
for theme in style.theme_names():
    print(theme)
Parameters
  • theme (str) – the name of the theme to use at runtime; flatly by default.

  • themes_file (str) – Path to a user-defined themes file. Defaults to the themes file set in ttkcreator.

configure(style, query_opt=None, **kw)[source]

Query or sets the default value of the specified option(s) in style.

Each key in kw is an option and each value is either a string or a sequence identifying the value for that option.

element_create(elementname, etype, *args, **kw)[source]

Create a new element in the current theme of given etype.

element_names()[source]

Returns the list of elements defined in the current theme.

element_options(elementname)[source]

Return the list of elementname’s options.

layout(style, layoutspec=None)[source]

Define the widget layout for given style. If layoutspec is omitted, return the layout specification for given style.

layoutspec is expected to be a list or an object different than None that evaluates to False if you want to “turn off” that style. If it is a list (or tuple, or something else), each item should be a tuple where the first item is the layout name and the second item should have the format described below:

LAYOUTS

A layout can contain the value None, if takes no options, or a dict of options specifying how to arrange the element. The layout mechanism uses a simplified version of the pack geometry manager: given an initial cavity, each element is allocated a parcel. Valid options/values are:

side: whichside

Specifies which side of the cavity to place the element; one of top, right, bottom or left. If omitted, the element occupies the entire cavity.

sticky: nswe

Specifies where the element is placed inside its allocated parcel.

children: [sublayout… ]

Specifies a list of elements to place inside the element. Each element is a tuple (or other sequence) where the first item is the layout name, and the other is a LAYOUT.

lookup(style, option, state=None, default=None)[source]

Returns the value specified for option in style.

If state is specified it is expected to be a sequence of one or more states. If the default argument is set, it is used as a fallback value in case no specification for option is found.

map(style, query_opt=None, **kw)[source]

Query or sets dynamic values of the specified option(s) in style.

Each key in kw is an option and each value should be a list or a tuple (usually) containing statespecs grouped in tuples, or list, or something else of your preference. A statespec is compound of one or more states and then a value.

register_theme(definition)[source]

Registers a theme definition for use by the Style class.

This makes the definition and name available at run-time so that the assets and styles can be created.

Parameters

definition (ThemeDefinition) – an instance of the ThemeDefinition class

theme_create(themename, parent=None, settings=None)[source]

Creates a new theme.

It is an error if themename already exists. If parent is specified, the new theme will inherit styles, elements and layouts from the specified parent theme. If settings are present, they are expected to have the same syntax used for theme_settings.

theme_names()[source]

Returns a list of all known themes.

theme_settings(themename, settings)[source]

Temporarily sets the current theme to themename, apply specified settings and then restore the previous theme.

Each key in settings is a style and each value may contain the keys ‘configure’, ‘map’, ‘layout’ and ‘element create’ and they are expected to have the same format as specified by the methods configure, map, layout and element_create respectively.

theme_use(themename=None)[source]

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.

Keyword Arguments

themename (str) – the theme to apply when creating new widgets

StylerTTK

class ttkbootstrap.StylerTTK(style, definition)[source]

Bases: object

A class to create a new ttk theme.

Create a new ttk theme by using a combination of built-in themes and some image-based elements using pillow. A theme is generated at runtime and is available to use with the Style class methods. The base theme of all ttkbootstrap themes is clam. In many cases, widget layouts are re-created using an assortment of elements from various styles such as clam, alt, default, etc…

theme_images

theme assets used for various widgets.

Type

dict

settings

settings used to build the actual theme using the theme_create method.

Type

dict

styler_tk

an object used to style tkinter widgets (not ttk).

Type

StylerTk

theme

the theme settings defined in the themes.json file.

Type

ThemeDefinition

Parameters
  • style (Style) – an instance of ttk.Style.

  • definition (ThemeDefinition) – an instance of ThemeDefinition; used to create the theme settings.

create_theme()[source]

Create and style a new ttk theme. A wrapper around internal style methods.

update_ttk_theme_settings()[source]

Update the settings dictionary that is used to create a theme. This is a wrapper on all the _style_widget methods which define the layout, configuration, and styling mapping for each ttk widget.

StylerTK

class ttkbootstrap.StylerTK(styler_ttk)[source]

Bases: object

A class for styling tkinter widgets (not ttk).

Several ttk widgets utilize tkinter widgets in some capacity, such as the popdownlist on the ttk.Combobox. To create a consistent user experience, standard tkinter widgets are themed as much as possible with the look and feel of the ttkbootstrap theme applied. Tkinter widgets are not the primary target of this project; however, they can be used without looking entirely out-of-place in most cases.

master

the root window.

Type

Tk

theme

the color settings defined in the themes.json file.

Type

ThemeDefinition

Parameters

styler_ttk (StylerTTK) – an instance of the StylerTTK class.

style_tkinter_widgets()[source]

A wrapper on all widget style methods. Applies current theme to all standard tkinter widgets

ThemeDefinition

class ttkbootstrap.ThemeDefinition(name='default', themetype='light', font='helvetica', colors=None)[source]

Bases: object

A class to provide defined name, colors, and font settings for a ttkbootstrap theme.

Parameters
  • name (str) – the name of the theme; default is ‘default’.

  • themetype (str) – the type of theme: light or dark; default is ‘light’.

  • font (str) – the default font to use for the application; default is ‘helvetica’.

  • colors (Colors) – an instance of the Colors class. One is provided by default.

Widgets

Button

class ttkbootstrap.widgets.Button(parent=None, **kwargs)[source]

Bases: tkinter.ttk.Button

Ttk button widget, displays as a textual label and/or image, and evaluates a command when pressed.

Parameters

parent (Widget) – The parent widget.

Keyword Arguments
  • class (str) – Specifies the window class. The class is used when querying the option database for the window’s other options, to determine the default bindtags for the window, and to select the widget’s default layout and style. This is a read-only option; it may only be specified when the window is created, and may not be changed with the configure widget command.

  • compound (str) – Specifies if the widget should display text and bitmaps/images at the same time, and if so, where the bitmap/image should be placed relative to the text. Must be one of the values none, bottom, top, left, right, or center. For example, the (default) value none specifies that the bitmap or image should (if defined) be displayed instead of the text, the value left specifies that the bitmap or image should be displayed to the left of the text, and the value center specifies that the bitmap or image should be displayed underneath the text.

  • cursor (str) – Specifies the mouse cursor to be used for the widget. Names and values will vary according to your operating system. Examples can be found here: https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/cursors.html

  • image (PhotoImage or str) – Specifies an image to display in the widget, which must have been created with tk.PhotoImage or TkPhotoImage` if using pillow. Can also be a string representing the name of the photo if the photo has been given a name using the name parameter. Typically, if the image option is specified then it overrides other options that specify a bitmap or textual value to display in the widget, though this is controlled by the compound option; the image option may be reset to an empty string to re-enable a bitmap or text display.

  • state (str) – May be set to normal or disabled to control the disabled state bit. This is a write-only option; setting it changes the widget state, but the state widget command does not affect the state option.

  • style (str) – May be used to specify a custom widget style.

  • takefocus (bool) – Determines whether the window accepts the focus during keyboard traversal (e.g., Tab and Shift-Tab). To remove the widget from focus traversal, use takefocus=False.

  • text (str) – Specifies a string to be displayed inside the widget.

  • textvariable (StringVar or str) – Specifies the name of a variable. Use the StringVar or the string representation if the variable has been named. The value of the variable is a text string to be displayed inside the widget; if the variable value changes then the widget will automatically update itself to reflect the new value.

  • underline (int) – Specifies the integer index of a character to underline in the widget. This option is used by the default bindings to implement keyboard traversal for menu buttons and menu entries. 0 corresponds to the first character of the text displayed in the widget, 1 to the next character, and so on.

  • width (int) – If the label is text, this option specifies the absolute width of the text area on the button, as a number of characters; the actual width is that number multiplied by the average width of a character in the current font. For image labels, this option is ignored. The option may also be configured in a style.

  • command (func) – A callback function to evaluate when the widget is invoked.

invoke()[source]

Invokes the command associated with the button.

Calendar

Classes and functions that enable the user to select a date.

ask_date
ttkbootstrap.widgets.calendar.ask_date(parent=None, startdate=None, firstweekday=6, style='TCalendar')[source]

Generate a popup date chooser and return the selected date

Parameters
  • parent (Widget) – The parent widget; the popup will appear to the bottom-right of the parent widget. If no parent is provided, the widget is centered on the screen.

  • firstweekday (int) – Specifies the first day of the week. 0 is Monday, 6 is Sunday (the default).

  • startdate (datetime) – The date to be in focus when the widget is displayed; defaults to the current date.

  • style (str) – The ttk style used to render the widget.

Returns

The date selected; the current date if no date is selected.

DateChooserPopup
class ttkbootstrap.widgets.calendar.DateChooserPopup(parent=None, firstweekday=6, startdate=None, style='TCalendar')[source]

Bases: object

A custom ttkbootstrap widget that displays a calendar and allows the user to select a date which is returned as a datetime object for the date selected.

The widget displays the current date by default unless a startdate is provided. The month can be changed by clicking on the chevrons to the right and left of the month-year title which is displayed on the top-center of the widget. A “left-click” will move the calendar one month. A “right-click” will move the calendar one year.

A “right-click” on the month-year title will reset the calendar widget to the starting date.

The starting weekday can be changed with the firstweekday parameter for geographies that do not start the week on Sunday, which is the widget default.

The widget grabs focus and all screen events until released. If you want to cancel a date selection, you must click on the “X” button at the top-right hand corner of the widget.

Styles can be applied to the widget by using the TCalendar style with the optional colors: ‘primary’, ‘secondary’, ‘success’, ‘info’, ‘warning’, and ‘danger’. By default, the primary.TCalendar style is applied.

Parameters
  • parent (Widget) – The parent widget; the popup is displayed to the bottom-right of the parent widget.

  • startdate (datetime) – The date to be in focus when the calendar is displayed. Current date is default.

  • firstweekday (int) – Specifies the first day of the week. 0 is Monday, 6 is Sunday (the default).

  • style (str) – The ttk style used to render the widget.

  • **kw

draw_calendar()[source]

Create the days of the week elements

draw_titlebar()[source]

Create the title bar

generate_widget_styles()[source]

Generate all the styles required for this widget from the base_style.

on_date_selected(index)[source]

Callback for selecting a date.

Assign the selected date to the date_selected property and then destroy the toplevel widget.

Parameters

index (Tuple[int]) – a tuple containing the row and column index of the date selected to be found in the monthdates property.

on_next_month()[source]

Callback for changing calendar to next month

on_next_year(*args)[source]

Callback for changing calendar to next year

on_prev_month()[source]

Callback for changing calendar to previous month

on_prev_year(*args)[source]

Callback for changing calendar to previous year

on_reset_date(*args)[source]

Callback for clicking the month-year title; reset the date to the start date

set_geometry()[source]

Adjust the window size based on the number of weeks in the month

setup()[source]

Setup the calendar widget

weekday_header()[source]

Creates and returns a list of weekdays to be used as a header in the calendar based on the firstweekday. The order of the weekdays is based on the firstweekday property.

Returns

a list of weekday headers

Return type

List

DateEntry
class ttkbootstrap.widgets.calendar.DateEntry(master=None, dateformat='%Y-%m-%d', firstweekday=6, startdate=None, style='TCalendar', **kw)[source]

Bases: tkinter.ttk.Frame

A date entry widget that combines a ttk.Combobox and a ttk.Button`` with a callback attached to the ask_date function.

When pressed, displays a date chooser popup and then inserts the returned value into the combobox.

Optionally set the startdate of the date chooser popup by typing in a date that is consistent with the format that you have specified with the dateformat parameter. By default this is %Y-%m-%d.

Change the style of the widget by using the TCalendar style, with the colors: ‘primary’, ‘secondary’, ‘success’, ‘info’, ‘warning’, ‘danger’. By default, the primary.TCalendar style is applied.

Change the starting weekday with the firstweekday parameter for geographies that do not start the week on Sunday, which is the widget default.

Parameters
  • master (Widget) – The parent widget.

  • dateformat (str) – The format string used to render the text in the entry widget. Default is ‘%Y-%m-%d’. For more information on date formats, see the python documentation or https://strftime.org/.

  • firstweekday (int) – Specifies the first day of the week. 0 is Monday, 6 is Sunday (the default).

  • startdate (datetime) – The date to be in focus when the calendar is displayed. Current date is default.

  • **kw – Optional keyword arguments to be passed to containing frame widget.

convert_system_color(systemcolorname)[source]

Convert a system color name to a hexadecimal value

Parameters

systemcolorname (str) – a system color name, such as SystemButtonFace

draw_button_image(color)[source]

Draw a calendar button image of the specified color

Image reference: https://www.123rf.com/photo_117523637_stock-vector-modern-icon-calendar-button-applications.html

Parameters

color (str) – the color to draw the image foreground.

Returns

the image created for the calendar button.

Return type

PhotoImage

generate_widget_styles()[source]

Generate all the styles required for this widget from the base_style.

Returns

the styles to be used for entry and button widgets.

Return type

Tuple[str]

on_date_ask()[source]

A callback for the date push button.

Try to grab the initial date from the entry if possible. However, if this date is not valid, use the current date and print a warning message to the console.

Floodgauge

class ttkbootstrap.widgets.Floodgauge(master=None, cursor=None, font=None, length=None, maximum=100, mode='determinate', orient='horizontal', style='TFloodgauge', takefocus=False, text=None, value=0, **kw)[source]

Bases: tkinter.ttk.Progressbar

A Floodgauge widget shows the status of a long-running operation with an optional text indicator.

Similar to the ttk.Progressbar, this widget can operate in two modes: determinate mode shows the amount completed relative to the total amount of work to be done, and indeterminate mode provides an animated display to let the user know that something is happening.

Variable are generated automatically for this widget and can be linked to other widgets by referencing them via the textvariable and variable attributes.

The text and value properties allow you to easily get and set the value of these variables without the need to call the get and set methods of the related tkinter variables. For example: Floodgauge.value or Floodgauge.value = 55 will get or set the amount used on the widget.

Parameters
  • master (Widget) – Parent widget

  • cursor (str) – The cursor that will appear when the mouse is over the progress bar.

  • font (Font or str) – The font to use for the progress bar label.

  • length (int) – Specifies the length of the long axis of the progress bar (width if horizontal, height if vertical); defaults to 300.

  • maximum (float) – A floating point number specifying the maximum value. Defaults to 100.

  • mode (str) – One of determinate or indeterminate. Use indeterminate if you cannot accurately measure the relative progress of the underlying process. In this mode, a rectangle bounces back and forth between the ends of the widget once you use the .start() method. Otherwise, use determinate if the relative progress can be calculated in advance. This is the default mode.

  • orient (str) – Specifies the orientation of the widget; either horizontal or vertical.

  • style (str) – The style used to render the widget; TFloodgauge by default.

  • takefocus (bool) – This widget is not included in focus traversal by default. To add the widget to focus traversal, use takefocus=True.

  • text (str) – A string of text to be displayed in the progress bar. This is assigned to the textvariable StringVar which is automatically generated on instantiation. This value can be get and set using the Floodgauge.text property without having to directly call the textvariable.

  • value – The current value of the progressbar. In determinate mode, this represents the amount of work completed. In indeterminate mode, it is interpreted modulo maximum; that is, the progress bar completes one “cycle” when the value increases by maximum.

  • **kw – Other configuration options from the option database.

start(interval=None)

Begin autoincrement mode: schedules a recurring timer event that calls method step every interval milliseconds.

interval defaults to 50 milliseconds (20 steps/second) if omitted.

step(amount=None)

Increments the value option by amount.

amount defaults to 1.0 if omitted.

stop()

Stop autoincrement mode: cancels any recurring timer event initiated by start.

Meter

class ttkbootstrap.widgets.Meter(master=None, arcrange=None, arcoffset=None, amounttotal=100, amountused=0, interactive=False, labelfont='Helvetica 10 bold', labelstyle='secondary.TLabel', labeltext=None, metersize=200, meterstyle='TMeter', metertype='full', meterthickness=10, showvalue=True, stripethickness=0, textappend=None, textfont='Helvetica 25 bold', textprepend=None, wedgesize=0, **kw)[source]

Bases: tkinter.ttk.Frame

A radial meter that can be used to show progress of long running operations or the amount of work completed; can also be used as a Dial when set to interactive=True.

This widget is very flexible. There are two primary meter types which can be set with the metertype parameter: ‘full’ and ‘semi’, which show the arc of the meter in a full or semi-circle. You can also customize the arc of the circle with the arcrange and arcoffset parameters.

The progress bar indicator can be displayed as a solid color or with stripes using the stripethickness parameter. By default, the stripethickness is 0, which results in a solid progress bar. A higher stripethickness results in larger wedges around the arc of the meter.

Various text and label options exist. The center text and progressbar is formatted with the meterstyle parameter and uses the TMeter styles. You can prepend or append text to the center text using the textappend and textprepend parameters. This is most commonly used for ‘$’, ‘%’, or other such symbols.

Variable are generated automatically for this widget and can be linked to other widgets by referencing them via the amountusedvariable and amounttotalvariable attributes.

The variable properties allow you to easily get and set the value of these variables. For example: Meter.amountused or Meter.amountused = 55 will get or set the amount used on the widget without having to call the get or set methods of the tkinter variable.

Parameters
  • master (Widget) – Parent widget

  • arcoffset (int) – The amount to offset the arc’s starting position in degrees; 0 is at 3 o’clock.

  • arcrange (int) – The range of the arc in degrees from start to end.

  • amounttotal (int) – The maximum value of the meter.

  • amountused (int) – The current value of the meter; displayed if showvalue=True.

  • interactive (bool) – Enables the meter to be adjusted with mouse interaction.

  • labelfont (Font or str) – The font of the supplemental label.

  • labelstyle (str) – The ttk style used to render the supplemental label.

  • labeltext (str) – Supplemental label text that appears below the center text.

  • metersize (int) – The size of the meter; represented by one side length of a square.

  • meterstyle (str) – The ttk style used to render the meter and center text.

  • metertype (str) – One of full or semi; displays a full-circle or semi-circle.

  • meterthickness (int) – The thickness of the meter’s progress bar.

  • showvalue (bool) – Show the meter’s value in the center text; default = True.

  • stripethickness (int) – The meter’s progress bar can be displayed in solid or striped form. If the value is greater than 0, the meter’s progress bar changes from a solid to striped, where the value is the thickness of the stripes.

  • textappend (str) – A short string appended to the center text.

  • textfont (Font or str) – The font of the center text.

  • textprepend (str) – A short string prepended to the center text.

  • wedgesize (int) – If greater than zero, the width of the wedge on either side of the current meter value.

convert_system_color(systemcolorname)[source]

Convert a system color name to a hexadecimal value

Parameters

systemcolorname (str) – a system color name, such as SystemButtonFace

draw_base_image()[source]

Draw the base image to be used for subsequent updates

draw_meter(*args)[source]

Draw a meter

Parameters

*args – if triggered by a trace, will be variable, index, mode.

draw_solid_meter(draw)[source]

Draw a solid meter

Parameters

draw (ImageDraw.Draw) – an object used to draw an arc on the meter

draw_striped_meter(draw)[source]

Draw a striped meter

Parameters

draw (ImageDraw.Draw) – an object used to draw an arc on the meter

lookup(style, option)[source]

Wrapper around the tcl style lookup command

Parameters
  • style (str) – the name of the style used for rendering the widget.

  • option (str) – the option to lookup from the style option database.

Returns

the value of the option looked up.

Return type

any

meter_value()[source]

Calculate the meter value

Returns

the value to be used to draw the arc length of the progress meter

Return type

int

on_dial_interact(e)[source]

Callback for mouse drag motion on indicator

Parameters

e (Event) – event callback for drag motion.

step(delta=1)[source]

Increase the indicator value by delta.

The default increment is 1. The indicator will reverse direction and count down once it reaches the maximum value.

Keyword Arguments

delta (int) – the amount to change the indicator.

Indices and tables