我正在尝试设置树形视图的样式
#Treeview Style
treeStyle = ttk.Style()
treeStyle.configure("mystyle.Treeview", highlightthickness=0, bd=0, font=('Arial', 11)) # Modify the font of the body
treeStyle.configure("mystyle.Treeview.Heading", font=('Arial', 13,'bold')) # Modify the font of the headings
treeStyle.layout("mystyle.Treeview", [('mystyle.Treeview.treearea', {'sticky': 'nswe'})]) # Remove the borders
#treeview Frame Widgets Define
EmployView=ttk.Treeview(treeviewFrame,style=treeStyle)
但是,当我运行上述代码时,出现此错误:
_tkinter.TclError: Layout <tkinter.ttk.Style object at 0x02FEAAF0> not found
我已经明确定义了样式,所以对于为什么找不到它感到困惑。
style
选项。此选项不期望Style
对象,而是字符串,在您的情况下为“ mystyle.Treeview”。小部件的样式只是形式为"<stylename>.<Layout>"
的字符串(如果不输入"<stylename>."
,它将更改默认小部件的样式),并使用Style
对象对其进行管理/裁剪。