ttk.Treeview – Change row background color

Treeview row background colors can be different for each row (or the same).

img

In the screenshot above, the root items have a yellow background while the sub-items have a light grey background.

1
2
3
4
5
6
7
8
9
# Define the row colors with a tag
treeview_products.tag_configure("product_row", background="yellow")
treeview_products.tag_configure("details_row", background="lightgrey")

# Insert the parent row - using the tag, 'product_row'
pizza_row = treeview_products.insert(parent="", index="end", text="Pizza", tag="product_row")

# Insert sub-row - using the tag, 'details_row'
treeview_products.insert(parent=pizza_row, index="end", values=("Cheese", "$0.89"), tag="details_row")