Nov-20-2022, 06:45 PM
(This post was last modified: Nov-20-2022, 07:14 PM by Yoriz.
Edit Reason: Added prefix
)
I have a treeview wich is populated from an sql DB:
Treeview:
Why for matching criteria (self.Var79) the tags are not blue?
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() |
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 ) |