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

标签 python layout styles element ttk

我在 Linux 上使用 python2.7。我开始尝试 ttk 风格。 我想知道在哪里可以找到小部件的完整布局。例如 TreeView 。

当我运行时:

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

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

我得到这个输出:

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

当我运行时:

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

我得到了所需的红色标题:

Treeview with red heading

我的问题是:

如何获取小部件的整体布局?

正如我在互联网上发现 Treeview.Heading 的存在一样。 为什么它没有出现在 s.layout的输出中?

最佳答案

这解决了它:

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)

关于Python ttk.Style : How to find all possible options to configure?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44910927/

相关文章:

python - 错误栏帽的线条样式

Java Swing 重绘和重新验证并不总是有效

css - 更多 CSS 工具包,例如 Twitter Bootstrap?

android - 我可以在代码中更改 Android 样式的父项吗?

python - 使用正则表达式匹配不同字符组顺序同时限制给定字符可以出现多少次的优雅方法?

python - 运行 jupyter notebook 时导入错误 : No module named IPython. 路径?

python - 异常时启动 IPython shell

java - JFrame 中的绘图窗口

java - 为什么将项目布局资源与Java源代码分开?

html - 将一个矩形替换为另一个 (html/css)