Python tkinter styleconfigure treeview4/23/2024 ![]() ![]() ![]() font1=To one of the option we can assign the font style like this. def my_upd(col): if col='white': nfigure('Treeview',background="white", fieldbackground="white", foreground="black") elif col='yellow': nfigure('Treeview',background="yellow", fieldbackground="yellow", foreground="black") else: nfigure('Treeview',background="black", fieldbackground="black", foreground="white")We can include the font style also. 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. On click of the radio button we will trigger the function my_upd(col) and we passed colour as parameter. We used on StringVar() with default value as 'black'. nfigure('Treeview', rowheight=100) Managing style using Radio buttonsUsing three RadioButtons we will configure the style of Treeview. style = ttk.Style(my_w) style.theme_use("clam") # set theam to nfigure("Treeview", background="black", fieldbackground="black", foreground="white")nfigure('Treeview.Heading', background="PowderBlue")The last line in above code adds different background color to headings. Note: To generate the above picture, you should add/change the aforementioned lines of code in the example Treeview: Basic example.Assigning default style for TreeviewThis is applied to all Treeview widgets. The result is a treeview with modified fonts on both the body and headings, no border and different colors for the rows: Tree.tag_configure('even', background='#DFDFDF') Then, for instance, a background color can be associated to the tags: tree.tag_configure('odd', background='#E8E8E8') ![]() ![]() If you would like to have a different format depending on the rows, you can make use of tags: tree.insert(folder1, "end", "", text="photo1.png", values=("23-Jun-17 11:28","PNG file","2.6 KB"),tags = ('odd',)) Then, the widget is created giving the above style: tree=ttk.Treeview(master,style="mystyle.Treeview") Style.layout("mystyle.Treeview", ) # Remove the borders nfigure("", font=('Calibri', 13,'bold')) # Modify the font of the headings nfigure("mystyle.Treeview", highlightthickness=0, bd=0, font=('Calibri', 11)) # Modify the font of the body In this case, we create a style "mystyle.Treeview" with the following code (see the comments to understand what each line does): style = ttk.Style() By taking Treeview: Basic example, it can be shown how to customize a basic treeview. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |