Python Forum
[Tkinter] Different rows colours in treeview tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Different rows colours in treeview tkinter
#1
I have a treeview wich is populated from an sql DB:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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?
Reply
#2
tag = is a tuple.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter - update/refresh treeview snakes 5 28,596 Dec-02-2023, 07:05 PM
Last Post: aynous19
  [Tkinter] How to insert data json to treeview tkinter? Shakanrose 8 9,718 Jan-19-2023, 03:58 PM
Last Post: Shakanrose
  [Tkinter] About Tkinter Treeview.selection_get() usage. water 3 12,732 Feb-12-2022, 02:19 PM
Last Post: water
  [Tkinter] [split] Is there a way to embed a treeview as a row inside another treeview? CyKlop 5 5,100 Oct-20-2021, 12:14 AM
Last Post: CyKlop
  [Tkinter] acceleration of data output in treeview tkinter Vladimir1984 4 6,211 Nov-21-2020, 03:43 PM
Last Post: Vladimir1984
  [Tkinter] Tkinter timetabl using treeview mntfr 3 4,262 Feb-05-2019, 09:36 PM
Last Post: Larz60+
  sQlite3 output to tkinter treeview - how do I set / increase width of the output? dewijones67 5 8,206 Jan-23-2019, 08:45 AM
Last Post: Larz60+
  [Tkinter] Aligning Python Tkinter Buttons In Rows TollyThaWally 3 9,162 Feb-22-2018, 02:56 AM
Last Post: woooee
  bind hover on tkinter.ttk.Treeview Larz60+ 4 17,671 May-20-2017, 10:28 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020