O'Reilly logo

Python GUI Programming with Tkinter by Alan D. Moore

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exploring a Ttk widget

To get a better picture of how a Ttk widget is built, open a shell in IDLE and import tkinter, ttk, and pprint:

>>> import tkinter as tk
>>> from tkinter import ttk
>>> from pprint import pprint

Now, create a root window, Combobox, and Style object:

>>> root = tk.Tk()
>>> cb = ttk.Combobox(root)
>>> cb.pack()
>>> style = ttk.Style()

The Style object is, perhaps, slightly misnamed; it doesn't point to a single style, but rather gives us a handle to examine and alter the styles, layouts, and maps for the current theme.

In order to examine our Combobox, we'll first get its stylename using the winfo_class() method:

>>> cb_stylename = cb.winfo_class()
>>> print(cb_stylename)
TCombobox

We can then inspect the layout of the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required