The Style Class is something new introduced by ttk, in order to improve upon Tkinter, and address a common complaint against it. Tkinter keeps both it’s logic code and styling options in the same area, whereas ttk uses the Style class to separate the styling from the widget logic.
ttk also expands upon the styling concept in Tkinter, for example, allowing us to create a style once, and then apply it on many widgets without having to re-write any code.
Table of Contents:
- Creating your own ttk Style
- Using Default ttk Styles
- ttk Themes
- List of Default Styles
Creating your own ttk Style
The first thing we will do in this ttk Tutorial, is explore how to create our own styles. (Default ttk Styles will be discussed later on).
Example# 1
In this example we’ll create a custom style for a ttk Button. When creating a style, we need a name for it which we will later assign in the style option for the widget. We use the naming convention “Name” + “.” + “Default Style”. So for the Button, whose default style name is “TButton”, we could call it “Custom.TButton”.
Using the style.configure() method, we can make changes to any style and also create any style. If the style name doesn’t exist, it will be created. We can change options like foreground, background, padding etc.
import tkinter as tk
import tkinter.ttk as ttk
class Window:
def __init__(self, master):
self.master = master
frame = ttk.Frame(self.master)
style = ttk.Style()
style.configure("Custom.TButton",
foreground="black",
background="white",
padding=[10, 10, 10, 10],
font="Verdana 12 underline")
bttn = ttk.Button(frame, text="Click Me!", style="Custom.TButton")
bttn.pack()
frame.pack(padx = 5, pady = 5)
root = tk.Tk()
root.geometry("200x150")
window = Window(root)
root.mainloop()
The output:

Now any widget we create and assign the Custom.TButton style, will have these attributes. It’s much simpler than having to rewrite the same options for each widget individually, which is what would happen in Tkinter, without ttk.
Example# 2
Let’s try another example, but for the Label instead this time.
class Window:
def __init__(self, master):
self.master = master
frame = ttk.Frame(self.master)
style = ttk.Style()
style.configure("Custom.TLabel",
foreground="white",
background="black",
padding=[10, 10, 10, 10],
relief="raised")
label = ttk.Label(frame, text="Hello World", style="Custom.TLabel")
label.pack(padx = 5, pady = 5)
frame.pack(padx = 5, pady = 5)
root = tk.Tk()
root.geometry("200x150")
window = Window(root)
root.mainloop()
The output:

Refer to the bottom of this tutorial, for a complete list of default styles and their names. Also, if you end up customizing alot of your widget styles, you might want to consider defining your TTK styles in a separate file, and importing them from there.
Using Default Styles
We don’t always have to create a new style though. We have default styles as well which are enabled by default.
The below example shows a few widgets created with the default widget styles assigned to them.
import tkinter as tk
import tkinter.ttk as ttk
class Window:
def __init__(self, master):
self.master = master
button = ttk.Button(self.master, text = "Click Me!")
button.pack(padx = 5, pady = 5)
label = ttk.Label(self.master, text = "This is a Label!")
label.pack(padx = 5, pady = 5)
checkbox = ttk.Combobox(self.master, values=["Option 1","Option 2"])
checkbox.set("Option 1")
checkbox.pack(padx = 5, pady = 5)
radiobutton = ttk.Radiobutton(self.master, text="Radio Button")
radiobutton.pack(padx = 5, pady = 5)
checkbutton = ttk.Checkbutton(self.master, text="Check Button")
checkbutton.pack(padx = 5, pady = 5)
scale = ttk.Scale(self.master, from_=0, to=10)
scale.pack(padx = 5, pady = 5)
entry = ttk.Entry(self.master)
entry.pack(padx = 5, pady = 5)
root = tk.Tk()
root.geometry('200x220')
window = Window(root)
root.mainloop()
The output:
