简体   繁体   English

Python ttk.Style:如何找到所有可能的配置选项?

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

I'm using python2.7 on Linux.我在 Linux 上使用 python2.7。 I started experimenting with ttk styles.我开始尝试 ttk 样式。 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:我得到了想要的红色标题:

带有红色标题的树状视图

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.正如我在互联网上发现的Treeview.Heading的存在。 Why does it not appear in the output of s.layout ?为什么它没有出现在s.layout的输出中

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM