我想要我的ttl.树视图表有一个交替的颜色模式,我试图添加标签,使每一个奇数行的背景不同,通过使用标签配置方法,但我一直未能做到。你知道吗
每一行都是我要显示的db表中的一行。你知道吗
我也试着在一个单独的小程序中这样做,但也没有效果。你知道吗
def show(self, row, column, rowspan):
self.row = row
self.column = column
self.rowspan = rowspan
global FondoBase
self.Tabla = ttk.Treeview(FondoBase, columns=self.Columnas[1:], height=40)
self.Tabla.heading("#0", text=self.Columnas[0])
for i in self.Columnas[1:]:
self.Tabla.heading("{}".format(i), text="{}".format(i))
self.Tabla.grid(row=row, column=column, rowspan=rowspan, sticky="e", pady=30)
scrol = Scrollbar(FondoBase, command=self.Tabla.yview)
self.Tabla.config(yscrollcommand=scrol.set)
scrol.grid(row=row, column=column+1, sticky="wns", rowspan=rowspan, pady=30)
Conexion = connect('{}'.format(Directorio))
with Conexion:
Seleccion = Conexion.cursor()
Seleccion.execute("""SELECT * FROM {}""".format(self.nombre))
resultado = Seleccion.fetchall()
for i in range(len(resultado)):
if i%2 == 0:
self.Tabla.insert("", i, text="{}".format(resultado[i][0]), values=(resultado[i][1:]), tags=("par"))
self.Tabla.tag_configure("par", background="#00ffff")
else:
self.Tabla.insert("", i, text="{}".format(resultado[i][0]), values=(resultado[i][1:]), tags=("impar"))
我真的不知道发生了什么。你知道吗
-您在cmd中使用的是什么版本的python(python-V)
-python的最后一个版本(3.7)似乎对颜色标签有bug
-如果您使用的是最新版本,请安装python 3.6
-你的一个标签没有颜色
相关问题 更多 >
编程相关推荐