首页 > 解决方案 > 未找到 tkinter 样式

问题描述

我正在尝试设置我的树视图的样式

#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

我已经明确定义了样式,所以我对为什么找不到它感到困惑。

标签: pythontkinterttk

解决方案


这里的问题是您没有将正确的参数传递给style树视图的选项。此选项不期望Style对象而是字符串,在您的情况下为“mystyle.Treeview”。小部件的样式只是表单的字符串"<stylename>.<Layout>"(如果您不输入"<stylename>.",它将更改默认小部件的样式),并且使用Style对象对其进行管理/剪切。


推荐阅读