Note: To generate the above picture, you should add/change the aforementioned lines of code in the example Treeview: Basic example. 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') Following is my code: def displaydevicestatus(self, colnames): root Tk(). Tree.insert(folder1, "end", "", text="photo2.png", values=("23-Jun-17 11:29","PNG file","3.2 KB"),tags = ('even',)) I am trying to change the background color of the rows in treeview using tags but unable to get the success. 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',)) On click of the radio button we will trigger the function myupd(col) and we passed colour as parameter. We used on StringVar() with default value as 'black'. ![]() Then, the widget is created giving the above style: tree=ttk.Treeview(master,style="mystyle.Treeview") nfigure('Treeview', rowheight100) Managing style using Radio buttons Using three RadioButtons we will configure the style of Treeview. Style.layout("mystyle.Treeview", ) # Remove the borders To create a canvas widget, you create a new instance of the Canvas class from the tkinter module. The canvas widget is a blank area on which you can draw figures, create text, and place images. The Canvas widget allows you to build anything from custom widgets to complete user interfaces. nfigure("", font=('Calibri', 13,'bold')) # Modify the font of the headings The canvas widget is the most flexible widget in Tkinter. nfigure("mystyle.Treeview", highlightthickness=0, bd=0, font=('Calibri', 11)) # Modify the font of the body To do this, add the following line to your code, underneath the lines in which you pack the treeview scrollbars: Tree.tagconfigure ('tagname', background'red') This creates one tag you can use to influence the background color. You can use this to define the color of a treeview row. ![]() 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() The tree.insert method will take an argument called 'tags'. 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 |