[英]How to change the focus styling of a tkinter ttk.Treeview cell
Even though my Treeview has the option takefocue=False
, the text in the cells is still taking focus somehow. 即使我的Treeview具有选项
takefocue=False
,单元格中的文本仍会以某种方式成为焦点。 Specifically the text column when I do tree.insert('', tk.END, text='Some Text', values=5)
is taking focus, meaning there is a dashed line around Some Text
. 具体来说,当我执行
tree.insert('', tk.END, text='Some Text', values=5)
时,文本列将成为焦点,这意味着Some Text
周围有一条虚线。 I was able to find this resource , but I am not sure of the layout string I need to change. 我可以找到该资源 ,但是不确定是否需要更改布局字符串。
According to the Tcl/Tk wiki, the following 5 styles can be used to customize a ttk.Treeview()
widget: 根据Tcl / Tk Wiki,可以使用以下5种样式来自定义
ttk.Treeview()
小部件:
"Treeview"
"Treeview.Heading"
"Treeview.Row"
"Treeview.Cell"
"Treeview.Item"
Using .layout()
, you can retrieve the layout specifications of each style: 使用
.layout()
,您可以检索每种样式的布局规格:
style = ttk.Style()
style.layout("Treeview.Item")
It turns out that the "Treeview.Item"
style has a "Treeitem.focus"
layout mark. 事实证明,
"Treeview.Item"
样式具有"Treeitem.focus"
布局标记。 If you comment it out when overwriting the layout, the focus drawing behavior (and the dashed line) will disappear: 如果在覆盖布局时将其注释掉 ,则焦点绘图行为(和虚线)将消失:
style = ttk.Style()
style.layout("Treeview.Item",
[('Treeitem.padding', {'sticky': 'nswe', 'children':
[('Treeitem.indicator', {'side': 'left', 'sticky': ''}),
('Treeitem.image', {'side': 'left', 'sticky': ''}),
#('Treeitem.focus', {'side': 'left', 'sticky': '', 'children': [
('Treeitem.text', {'side': 'left', 'sticky': ''}),
#]})
],
})]
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.