Ttk Widgets

Summary: in this tutorial, you’ll learn about Tk themed widgets by using the Tkinter.ttk module.

Introduction to Tk themed widgets #

Tkinter has two generations of widgets:

  • The old classic tk widgets. Tkinter introduced them in 1991.
  • The newer themed ttk widgets added in 2007 with Tk 8.5. The newer Tk themed widgets replace many (but not all) classic widgets.

Note that ttk stands for Tk themed. Therefore, Tk themed widgets are the same as ttk widgets

The tkinter.ttk module contains all the new ttk widgets. It’s a good practice to always use themed widgets whenever they’re available.

The following statements import the classic and the new Tk themed widgets:

import tkinter as tk
from tkinter import ttkCode language: Python (python)

And the following program illustrates how to create classic and themed buttons:

import tkinter as tk
from tkinter import ttk

root = tk.Tk()

tk.Label(root, text='Classic Label').pack()
ttk.Label(root, text='Themed Label').pack()

root.mainloop()Code language: Python (python)

Output (on Windows 11):

tk vs ttk widgets

The first button is a classic tk button while the second one is a newer ttk button, which is native to Windows 11.

Advantages of using Tk themed widgets #

Here are the main advantages of using the Tk themed widgets:

  • Separating the widget’s behavior and appearance – the ttk widgets attempt to separate the code that implements the widgets’ behaviors from their appearance through the styling system.
  • Native look & feel – the ttk widgets have the native look and feel of the platform on which the program runs.
  • Simplify the state-specific widget behaviors – the ttk widgets simplify and generalize the state-specific widget behavior.

The ttk widgets #

The following ttk widgets replace the Tkinkter widgets with the same names:

And the following widgets are new and specific to ttk:

For the next tutorials, we’ll focus on using the themed widgets instead of the classic widgets.

Summary #

  • Tkinter has both classic and themed widgets (ttk widget). The Tk themed widgets are also known as ttk widgets.
  • The tkinter.ttk module contains all the ttk widgets.
  • Do use ttk widgets whenever they’re available.
Was this tutorial helpful ?