Nov-20-2022, 06:45 PM
I have a treeview wich is populated from an sql DB:
def fetch_data(): con = pymysql.connect(host='localhost', user='root', password='*', database='*') cur = con.cursor() cur.execute('select Var60,' 'Var61, Var62, Var63, Var64, Var65, Var66, Var67, Var68, Var69, Var70, operator from prices order by crt desc') rows = cur.fetchall() if rows != 0: self.totalrecord.set(len(rows)) table.delete(*table.get_children()) for row in rows: if self.Var79 == 'A': table.insert("", END, values=row, tags='Blue') else: table.insert("", END, values=row, tags='White') con.commit() con.close()Treeview:
style = ttk.Style() style.configure('Treeview', background='white') style.map('Treeview', background=[('selected', 'blue')]) view_frame = Frame(data_frame, bd=5, relief='flat', bg='#D9E9EC') view_frame.place(x=1, y=25, width=1185, height=300) x_scroll = Scrollbar(view_frame, orient=HORIZONTAL) y_scroll = Scrollbar(view_frame, orient=VERTICAL) table = ttk.Treeview(view_frame, xscrollcommand=x_scroll.set, yscrollcommand=y_scroll.set, columns=( 'Var60', 'Var61', 'Var62', 'Var63', 'Var64', 'Var65', 'Var66', 'Var67', 'Var68', 'Var69', 'Var70')) x_scroll.pack(side=BOTTOM, fill=X) y_scroll.pack(side=RIGHT, fill=Y) table.tag_configure('Blue', background="blue") table.tag_configure('White', background="white") x_scroll.config(command=table.xview) y_scroll.config(command=table.yview) table.heading("Var60", text="Var60") table.heading("Var61", text="Var61") table.heading("Var62", text="Var62") table.heading("Var63", text="Var63") table.heading("Var64", text="Var64") table.heading("Var65", text="Var65") table.heading("Var66", text="Var66") table.heading("Var67", text="Var67") table.heading("Var68", text="Var68") table.heading("Var69", text="Var69") table['show'] = 'headings' table.bind('<ButtonRelease-1>', focus) fetch_data() table.pack(fill=BOTH, expand=1)Why for matching criteria (self.Var79) the tags are not blue?