我希望我的 ttk.treeview 有交替的颜色 [英] I want my ttk.treeview to have alternating colours

查看:34
本文介绍了我希望我的 ttk.treeview 有交替的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的 ttl.treeview 表具有交替的颜色模式,并且我尝试使用 tag_configure 方法添加标签并使每个奇数行的背景不同,但我无法做到.

I want my ttl.treeview table to have an alternating pattern of colours and I tried to add tags and make the background of each odd row distinct by using the tag_configure method, but I haven't been able.

每一行都是我想显示的数据库表中的一行.

Every row is a row taken from a db table that I want to show.

我也尝试过在一个小而独立的程序中这样做,但也没有效果.

I also tried to do so in a little and separate program, but it hasn't been effective either.

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"))

我真的不知道发生了什么.

I don't really know what's going on.

推荐答案

-你在cmd中使用的是什么版本的python(python -V)

-what version of python are you using (python -V) in cmd

-python 的最后一个版本(3.7)似乎有颜色标签的错误

-the last version(3.7) of python seems like it has bugs to color tags

-如果您使用的是最新版本,只需安装 python 3.6

-if your using the last version just install python 3.6

-您的一个标签没有颜色

-one of your tags doesn't have a color

self.Tabla.tag_configure("impar", background="#ff008c")

这篇关于我希望我的 ttk.treeview 有交替的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆