Applying Ttk styling
As we mentioned in the first recipe of this chapter, themed widgets have a specific API to customize their appearance. We cannot directly set options, such as the foreground color or the internal padding, because these values are set via the ttk.Style
class.
In this recipe, we will cover how to modify the widgets from the first recipe to add some styling options.
How to do it...
To add some default settings, we will simply need a ttk.Style
object, which offers the following methods:
configure(style, opts)
: Changes the appearanceopts
for a widgetstyle
. Here is where we set options such as the foreground color, padding, and relief.map(style, query)
: Changes the dynamic appearance for a widgetstyle
. The argumentquery
is a keywords argument where each key is a styling option, and values are lists of tuples of the(state, value)
form, meaning that the value of the option is determined by its current state.
For instance, we have marked the following examples of both situations...