Next / Previous / Contents

28. ttk: Themed widgets

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.

    • The activeforeground color option applies when the cursor is over the button.

    • The disabledforeground color is used when the widget is disabled.

    • The widget will have the foreground 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: disabled, active, and focus.

    • 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.