3

Even though my Treeview has the option takefocue=False, the text in the cells is still taking focus somehow. 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. I was able to find this resource, but I am not sure of the layout string I need to change.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
tristan957
  • 551
  • 2
  • 4
  • 14

1 Answers1

5

According to the Tcl/Tk wiki, the following 5 styles can be used to customize a ttk.Treeview() widget:

"Treeview"
"Treeview.Heading"
"Treeview.Row"
"Treeview.Cell"
"Treeview.Item"

Using .layout(), you can retrieve the layout specifications of each style:

style = ttk.Style()
style.layout("Treeview.Item") 

It turns out that the "Treeview.Item" style has a "Treeitem.focus" layout mark. 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': ''}),
    #]})
    ],
})]
)

enter image description here

Josselin
  • 2,593
  • 2
  • 22
  • 35