6

I'm building a Python GUI application using ttk treeviews. On Linux, when a Treeitem has child items, it displays an arrow to show that the row can be expanded. I want to hide this indicator arrow (I am using other ways to hint that the row can be expanded). How can I do this?

If I run Style().element_names() I see that there's a Treeview element and a Treeitem.indicator element. If I run Style().configure("Treeview", padding=50), I see the padding style get applied when I create the treeview, so I feel confident that any style I correctly apply to Treeitem.indicator should be visible also.

Running Style().element_options("Treeitem.indicator"), I see ('-foreground', '-indicatorsize', '-indicatormargins'). Running Style().lookup("Treeitem.indicator", "foreground") gives me "#000000", so it appears that value is initialized. If I try Style().configure("Treeview", foreground="#123456") I don't see the indicator arrow change color, though running Style.lookup("Treeitem.indicator", "foreground") shows me "#123456" as expected. My plan was to set the indicatorsize to 0 to make the arrow go away entirely, but I cannot even successfully edit the color. What am I doing wrong here and is there a better way to hide the indicator? In case it matters, I'm running Python 3.5.0.

Zeke
  • 1,974
  • 18
  • 33

1 Answers1

4

Not sure if you ever figured it out.

When you create the new style and configure it, you have to change the name of the template to ".". This changes the root style for the treeview. You also need to specify a theme, even if it is default. So it would look something like:

s = ttk.Style()
s.configure(".", indicatorsize = '0')
s.theme_use('default')

Then when you create the treeview, you shouldn't have to specify a style at all.

Let me know if this works for you.

Edit: Since this is being downvoted for some reason, I'll clarify:

Code with the style part commented out:

    #s = ttk.Style()
    #s.configure(".", indicatorsize = '0')
    #s.theme_use('clam')

    j = ttk.Treeview(self.parent)
    j.place(relx = 0.5, rely = 0.5, anchor = "center")
    j.insert("",1,"jacob",text = "Jacob")
    j.insert("jacob",1,"marcus",text = "Marcus")
    j.insert("jacob",2,"tony",text = "Tony")
    j.insert("jacob",3,"ricardo",text = "Ricardo")

gives us

enter image description hereenter image description here

Code with the style part present

s = ttk.Style()
s.configure(".", indicatorsize = '0')
s.theme_use('clam')

j = ttk.Treeview(self.parent)
j.place(relx = 0.5, rely = 0.5, anchor = "center")
j.insert("",1,"jacob",text = "Jacob")
j.insert("jacob",1,"marcus",text = "Marcus")
j.insert("jacob",2,"tony",text = "Tony")
j.insert("jacob",3,"ricardo",text = "Ricardo")

enter image description hereenter image description here

Hope this helps.

EDIT 2: Added the s.theme_use('clam') line because you need to specify which theme you're using. It also works with classic and default, but for some reason doesn't work with the vista theme.

RBuntu
  • 907
  • 10
  • 22
  • Not sure why this is being downvoted. I used this code and managed to make the indicator disappear completely in my test treeview. – RBuntu Sep 01 '16 at 13:52
  • It was me who had downvoted you cos I've tried your code on windows and it doesn't work as expected. In any case, now you've showed it works on linux I'll upvote you – BPL Sep 01 '16 at 14:21
  • @BPL This isnt Linux, I ran the code on Windows 7. I wasnt entirely sure why it wasnt working for you. I did some more poking around and it seems like you have to specify the theme to use before you can change the indicator size. It seems to work with `s.theme_use('default')`, as well as other themes like classic and clam. Doesnt seem to work with the vista theme however. – RBuntu Sep 01 '16 at 14:32
  • Cool stuff man! I've deleted my answer, bounty should go definitely for you on this. Good job ;) – BPL Sep 01 '16 at 14:38
  • Thanks, appreciate it! – RBuntu Sep 01 '16 at 14:44