Search code examples
pythonlayoutstyleselementttk

Python ttk.Style: How to find all possible options to configure?


I'm using python2.7 on Linux. I started experimenting with ttk styles. I wondered where to find the complete Layout of a widget. For example a Treeview.

When I run:

import ttk
from pprint import pprint
s = ttk.Style()
ttk.Treeview().pack()

layout = s.layout('Treeview')
pprint(layout)

I get this output:

[('Treeview.field',
  {'border': '1',
   'children': [('Treeview.padding',
                 {'children': [('Treeview.treearea', {'sticky': 'nswe'})],
                  'sticky': 'nswe'})],
   'sticky': 'nswe'})]

When I run:

s.configure('Treeview.Heading', background='red')

I get the desired red heading:

Treeview with red heading

My question is:

How do I get the whole layout of the widgets?

As I have found out about the existence of Treeview.Heading on the internet. Why does it not appear in the output of s.layout?


Solution

  • This solved it:

    import tkinter.ttk as ttk
    from pprint import pprint
    
    s = ttk.Style()
    data = {}
    for e in s.element_names():
        data[e] = s.element_options(e)
    
    pprint(data)