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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.