Starting with Tk 8.5, the ttk module became available. This module replaces much (but not all) of the original Tkinter machinery. Use this module to gain these advantages:
Platform-specific appearance. In releases before Tk 8.5, one of the commonest complaints about Tk applications was that they did not conform to the style of the various platforms.
The ttk module allows you to write your application in a generic way, yet your application can look like a Windows application under Windows, like a MacOS app under MacOS, and so on, without any change to your program.
Each possible different appearance is represented by a named
ttk theme. For example, the
classic theme gives you the appearance of the
original Tkinter widgets described in the previous sections.
Simplification and generalization of state-specific widget behavior. In the basic Tkinter world, there are a lot of widget options that specify how the widget should look or behave depending on various conditions.
For example, the
tk.Button widget has several
different options that control the foreground (text) color.
activeforeground color option applies
when the cursor is over the button.
disabledforeground color is used when
the widget is disabled.
The widget will have the
color when the other conditions don't apply.
The ttk module collapses a lot of these special cases into a simple two-part system:
Every widget has a number of different states, and each
state can be turned on or off independently of the
others. Examples of states are:
You can set up a style map that specifies that certain options will be set to certain values depending on some state or some combination of the widget's states.
To use ttk, you will need to know these things.
Section 28.1, “Importing ttk”: Setting up your program to use ttk.
Section 28.2, “The ttk widget set”: The new and replaced ttk widgets.
There are different ways to import the ttk module.
If you prefer that all the widgets and other features of Tkinter and ttk be in your global namespace, use this form of import:
from Tkinter import * from ttk import *
It is important to do these two imports in this order,
so that all the widget types from ttk replace the
equivalent widgets from Tkinter. For example, all your
Button widgets will come from ttk
and not Tkinter.
In more complex applications, where you are using
more than one imported module, it can greatly improve
the readability of your code if you practice
safe namespace hygiene:
import all your modules using the “
import ” syntax. This requires just a bit more
typing, but it has the great advantage that you can
look at a reference to something and tell where it
We recommend this form of import:
So after this import,
ttk.Label is the
Label widget constructor,
ttk.Button is a
Button, and so
If you need to refer to items from the Tkinter module, it
is available as
ttk.Tkinter. For example,
the anchor code for “northeast” is
You may instead import Tkinter separately in this way:
import Tkinter as tk
After this form of import, the code for