所以我的问题非常简单,如何在Python中更改树视图中标题的颜色?
我在网上找到了这个选项:
ttk.Style().configure("Treeview.Heading", background="black")
但它似乎不适用于我的代码(标题只保留默认颜色)
其他问题,如何更改树中所选行的颜色?
这是我的代码:
class CTABLE:
def __init__(self, master):
self.charactersTable = ttk.Treeview(master, selectmode="browse")
self.charactersTable["show"] = "headings"
self.charactersTable["columns"]=("Name", "Surname", "Hunger",
"Fear", "Comfort", "Hapiness")
self.charactersTable.column("Name", width=100, anchor=E)
self.charactersTable.heading("Name", text="Name")
self.charactersTable.column("Surname", width=100, anchor=E)
self.charactersTable.heading("Surname", text="Surname")
self.charactersTable.column("Hunger", width=100, anchor=E)
self.charactersTable.heading("Hunger", text="Hunger")
self.charactersTable.column("Fear", width=100, anchor=E)
self.charactersTable.heading("Fear", text="Fear")
self.charactersTable.column("Comfort", width=100, anchor=E)
self.charactersTable.heading("Comfort", text="Comfort")
self.charactersTable.column("Hapiness", width=100, anchor=E)
self.charactersTable.heading("Hapiness", text="Hapiness")
for character in characters:
self.charactersTable.insert("", "end", values=(character.surname, character.name,
character.hunger, character.fear, character.comfort,
character.happiness))
self.charactersTable.bind("<Double-1>", self.CTClick)
self.charactersTable.grid(row=3, rowspan=3, column=1, columnspan = 4)
ctable = CTABLE(CharactersPage)
ttk.Style().configure("Treeview", background="#636363",foreground="white")
ttk.Style().configure("Treeview.Heading", background="black")
root.mainloop()