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

Get Python GUI Programming - A Complete Reference Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.