0

The first treeview which had a particular style was:

class tree:
    def __init__(self):
        self.tree = ttk.Treeview(frametree,height=28)
        self.tree.grid(row=1,column=0,padx=2)
        self.tree.column("#0",width=250, stretch=NO)
        self.tree.bind("<ButtonRelease-1>", self.OnClick)
        self.tree.tag_configure('highlight', background='lightblue')
        style_def = ttk.Style(frametree)
        style_def.configure("Treeview", background="#FFDEAD",fieldbackground="#FFDEAD", foreground="Black", font=(None, 14), sheight=14, rowheight=30)
        style_def.configure("Treeview.Heading",font=(None, 12))

The following code was used for showing the treeview:

# for displaying treeview
#tree000 = tree()
if __name__ == "__main__":
    tree000 = tree()

The another table was styled in different way as follows:

style_wear = ttk.Style(firsttreeframe)
style_wear.configure("Treeview.Heading", font=(None, 13))
style_wear.configure("Treeview", font=(None, 12))
tree02 = ttk.Treeview(firsttreeframe, column=("c1", "c2","c3", "c4","c5", "c6","c7", "c8","c9","c10", "c11","c12", "c13","c14", "c15","c16", "c17","c18"), show='headings', height=5)

And finally used grid method to place the treeview table.

tree02['show']='headings'
tree02.grid(row=1,column=0,columnspan=4,sticky=EW)

But tree1 gets the style of first tree. I don't know why maybe because of treeview display method.

I tried running placing the treeview in separate project It works fine as you can see:

In app first tree: first tree Second tree: tree1 second tree You can see both has same style In separate project: separate project I want my app to show this style to the second tree but it gets the style of the first tree. Please help me with this.

JRiggles
  • 4,847
  • 1
  • 12
  • 27
  • 2
    Using "Treeview" as the style name will affect all instances of `Treeview`. Use different style names for the two trees, for example "tree1.Treeview" and "tree2.Treeview" and set the `style` option of the two treeviews correspondingly. – acw1668 Jan 10 '23 at 08:56
  • Do you mean like this? ```style_measurement = ttk.Style(secondframe) style_measurement.configure("tree1.Treeview.Heading", font=(None, 13)) style_measurement.configure("tree1.Treeview", font=(None, 12))``` It still does not work this change sets the treeview style to default. – Prashant Priyadarshi Jan 10 '23 at 10:08
  • As I said, you need to apply the style to the treeview you want by setting the `style` option of the treeview. – acw1668 Jan 10 '23 at 10:11
  • Yeah now I got you point. ```style_wear.configure("fortree1.Treeview",background="yellow", foreground="black",fieldbackground="red") style_wear.map('fortree1.Treeview', background=[('selected','green')],foreground=[('selected','black')]) tree02 = ttk.Treeview(w, column=("c1", "c2","c3",), show='headings', height=5,style="fortree2.Treeview")``` Thank you so much – Prashant Priyadarshi Jan 10 '23 at 11:09
  • But if I configure the headings in the same way how could it be done? The headings does not accept the style arguments. – Prashant Priyadarshi Jan 10 '23 at 11:40
  • Sorry to Disturb you again. I did it using ```style_defect.configure('fordefect.Treeview.Heading', background="green3")``` Thank you so much for your help – Prashant Priyadarshi Jan 10 '23 at 11:55

0 Answers0