在以下Python代码中,我尝试更改Treeview表中行的颜色。没用我尝试使用tag.configure但... 如您所见,该函数的作用是从sql数据库中提取数据并将其放入Treeview表中,根据颜色的不同,该行应有所不同,但它不起作用... anu帮助吗?
from tkinter import *
from tkinter import ttk
import sqlite3
root=Tk()
FrameTabla=Frame(root)
FrameTabla.pack()
def mostrar_items():
miConexion=sqlite3.connect("database")
miCursor=miConexion.cursor()
miCursor.execute("SELECT * FROM DATABASE ORDER BY USERID DESC")
lista=miCursor.fetchall()
for i in lista:
if lista.index(i) % 2 == 0:
Tabla.insert('', 0, text=i[0], values=(i[1], i[2]), tags=('par',))
else:
Tabla.insert('', 0, text=i[0], values=(i[1], i[2]), tags=('impar',))
miConexion.close()
Tabla=ttk.Treeview(FrameTabla, heigh=20, columns=("Nombre", "Apellido"))
Tabla.grid(row=0, column=0, columnspan=3)
Tabla.tag_configure('par',background='white',foreground='black')
Tabla.tag_configure('impar',background='black',foreground='white')
Tabla.heading('#0', text = 'UserID', anchor = CENTER)
Tabla.heading('Nombre', text = 'Nombre', anchor = CENTER)
Tabla.heading('Apellido', text = 'Apellido', anchor = CENTER)
Tabla.column('#0', width=120, anchor= CENTER)
Tabla.column('Nombre', anchor = CENTER)
Tabla.column('Apellido', anchor = CENTER)
ScrollVert=Scrollbar(FrameTabla, command=Tabla.yview)
ScrollVert.grid(row=0, column=4, sticky='nsew')
mostrar_items()
root.mainloop()