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
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:

                for row in rows:
                    if self.Var79 == 'A':
                        table.insert("", END, values=row, tags='Blue')
                        table.insert("", END, values=row, tags='White')

 style = ttk.Style()
                  background=[('selected', 'blue')])

        view_frame = Frame(data_frame, bd=5, relief='flat', bg='#D9E9EC'), 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=(
            '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")

        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)
        table.pack(fill=BOTH, expand=1)
Why for matching criteria (self.Var79) the tags are not blue?
tag = is a tuple.

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter - update/refresh treeview snakes 5 20,926 Dec-02-2023, 07:05 PM
Last Post: aynous19
  [Tkinter] How to insert data json to treeview tkinter? Shakanrose 8 4,438 Jan-19-2023, 03:58 PM
Last Post: Shakanrose
  [Tkinter] About Tkinter Treeview.selection_get() usage. water 3 8,313 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 3,376 Oct-20-2021, 12:14 AM
Last Post: CyKlop
  [Tkinter] acceleration of data output in treeview tkinter Vladimir1984 4 4,205 Nov-21-2020, 03:43 PM
Last Post: Vladimir1984
  [Tkinter] Tkinter timetabl using treeview mntfr 3 3,243 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 6,665 Jan-23-2019, 08:45 AM
Last Post: Larz60+
  [Tkinter] Aligning Python Tkinter Buttons In Rows TollyThaWally 3 8,023 Feb-22-2018, 02:56 AM
Last Post: woooee
  bind hover on tkinter.ttk.Treeview Larz60+ 4 15,062 May-20-2017, 10:28 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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