更改不同树视图的行高

时间:2018-07-04 08:53:30

标签: python tkinter

我有2个树视图,我想将第一个树视图的行高设置为45。我使用style,但是当我更改第一个树视图的行高时,它会自动更改第二个树视图的行高。

我在做什么错了?

from tkinter import *
from tkinter import ttk

myApp = Tk()

#first tree with row height of 45

s = ttk.Style()
s.configure('Treeview', rowheight=45)

NewTree= ttk.Treeview(myApp, height=4, style='Treeview')
NewTree['show'] = 'headings'

NewTree["columns"]=("1","2")

NewTree.column("1", width=50)
NewTree.column("2", width=50)

NewTree.heading("1", text="Col A")
NewTree.heading("2", text="Col B")

item = NewTree.insert("", "end", values=("value 1","value 2"))

NewTree.grid(row=0,column=0,padx=5)

#second tree with defult row height (it automatically changed to 45)
#How to set different row heights to diferent treeviews?

SecondTree= ttk.Treeview(myApp, height=4)
SecondTree['show'] = 'headings'

SecondTree["columns"]=("1","2")

SecondTree.column("1", width=50)
SecondTree.column("2", width=50)

SecondTree.heading("1", text="Col A")
SecondTree.heading("2", text="Col B")

item = SecondTree.insert("", "end", values=("value 1","value 2"))

SecondTree.grid(row=0,column=1,padx=5)

myApp.mainloop()

1 个答案:

答案 0 :(得分:2)

#include <iostream> #include "point.h" int main() { class Point3D : public pt::Point { int z; public: getZ() { return this->z; } Point3D(int x ,int y, int z) { this->x=x; this->y=y; this->z=z; } }; return 0; } 样式是所有Treeview小部件使用的默认样式。如果更改此设置,则更改所有树视图。如果您只想更改一个Treeview,请根据默认的Treeview样式创建新样式,然后更改(reference):

Treeview