How can I set a style for treeview widgets so that alternate rows have different background colors, for example, rows 1,3,5 have white backgrounds and rows 2,4,6 have light blue-grey backgrounds?
I’d also like to set gridlines.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I had this same issue a few months ago.
From the tk docs:
Basically, you apply one tag to all of the odd-numbered rows, a different tag to each of the even-numbered rows, and then configure the tags.
When you create the items inside the treeview, add tags to them:
This code creates an element in
tree, and thetagsargument assigns the tag ‘oddrow’ to the element.Once you’ve created all your elements with ‘oddrow’ and ‘evenrow’ tags, you can color the tags: