";require "../templates/head_jq_bs4.php";echo "";echo "";$img_path="..";require "top-link-tkinter.php";require "templates/top_bs4.php"; echo "

Managing Style of Treeview

";require "templates/body_start.php";?>Managing Treeview Style

Assigning default style for Treeview

This is applied to all Treeview widgets.
style = ttk.Style(my_w) style.theme_use("clam") # set theam to clamstyle.configure("Treeview", background="black",                 fieldbackground="black", foreground="white")style.configure('Treeview.Heading', background="PowderBlue")
The last line in above code adds different background color to headings.

row height by using style.
style.configure('Treeview', rowheight=100) 

Managing style using Radio buttons

Using three RadioButtons we will configure the style of Treeview. We used on StringVar() with default value as 'black'. On click of the radio button we will trigger the function my_upd(col) and we passed colour as parameter.
r1 = tk.Radiobutton(my_w, text='Black', variable=r1_v, value='black',	command=lambda:my_upd('black'))
Inside the function my_upd() we will check the parameter value and accordingly update the style.
def my_upd(col):    if col=='white':        style.configure('Treeview',background="white",                 fieldbackground="white", foreground="black")    elif col=='yellow':        style.configure('Treeview',background="yellow",                 fieldbackground="yellow", foreground="black")    else:        style.configure('Treeview',background="black",                 fieldbackground="black", foreground="white")
We can include the font style also.
font1=['Times',12,'normal']
To one of the option we can assign the font style like this.
    elif col=='yellow':        style.configure('Treeview',background="yellow",                 fieldbackground="yellow", foreground="black",font=font1)
Configuring Tkinter Treeview style background foreground color using Radio buttons



from tkinter import ttkimport tkinter as tk# Creating tkinter my_wmy_w = tk.Tk()my_w.geometry("300x250") # width and height of the window my_w.title("www.plus2net.com")  trv=ttk.Treeview(my_w,selectmode='browse',show='headings',height=5)trv.grid(row=1,column=1,columnspan=3,padx=30,pady=10)# column identifiers trv["columns"] = ("1", "2")# Defining headings, other option is treetrv['show'] = 'headings tree' # width of columns and alignment trv.column("#0", width = 80, anchor ='c')trv.column("1", width = 10, anchor ='c')trv.column("2", width = 100, anchor ='c')# Headings  # respective columnstrv.heading("#0", text ="Label",anchor='c')trv.heading("1", text ="id")trv.heading("2", text ="Name",anchor='c')trv.insert("",'end',iid=1,text='First',values=(1,'n1-Alex'))trv.insert("",'end',iid=2,text='second',values=(2,'n2-Ravi'))trv.insert("",'end',iid=3,text='third',values=(3,'n3-Ronn'))style = ttk.Style(my_w) style.theme_use("clam") # set theam to clamstyle.configure("Treeview", background="black",                 fieldbackground="black", foreground="white")style.configure('Treeview.Heading', background="PowderBlue")r1_v = tk.StringVar(value='black')  # We used string variable heredef my_upd(col):    if col=='white':        style.configure('Treeview',background="white",                 fieldbackground="white", foreground="black")    elif col=='yellow':        style.configure('Treeview',background="yellow",                 fieldbackground="yellow", foreground="black")    else:        style.configure('Treeview',background="black",                 fieldbackground="black", foreground="white")r1 = tk.Radiobutton(my_w, text='Black', variable=r1_v, value='black',	command=lambda:my_upd('black'))r1.grid(row=2,column=1) r2 = tk.Radiobutton(my_w, text='White', variable=r1_v, value='white',	command=lambda:my_upd('white'))r2.grid(row=2,column=2) r3 = tk.Radiobutton(my_w, text='Yellow', variable=r1_v, value='yellow',	command=lambda:my_upd('yellow'))r3.grid(row=2,column=3) my_w.mainloop()

Dynamic Creation of Header & Columns in Treeview Display MySQL records in Treeview Pagination of MySQL records in Treeview
Displaying MySQL records using Entry or Label Delete MySQL record
TreeviewTreeview insert Treeview parent child nodeSelect -Edit-update MySQL Product table using Treeview