首页 > 解决方案 > 您可以在单个应用程序中创建多个 ttk 树视图标题样式吗?

问题描述

我有一个用 python 3 编写的 tkinter 应用程序,它在不同的顶层框架中使用多个树视图小部件。我想为每个小部件定制不同的标题样式,但我只知道如何更改全局“Treeview.Heading”样式。以下是我当前定义树视图样式的方式:

self.xs_font = tkfont.Font(family='Arial', size=9)
self.treeview = ttk.Style()
def fixed_map(option):#bug fix to allow highlighted lines in a treeview
    return [elm for elm in self.treeview.map('Treeview', query_opt=option) if elm[:2] != ('!disabled', '!selected')]
self.treeview.map('Treeview', foreground=fixed_map('foreground'),background=fixed_map('background'))#implement bug fix
self.treeview.configure('home_tree.Treeview',font=self.xs_font,rowheight=20)# style for homepage treeview
self.treeview.configure('toplevel_tree.Treeview',font=self.xs_font,rowheight=30)#style for toplevel treeview
self.treeview.configure('Treeview.Heading',font=self.xs_font,rowheight=20)#style for treeview headings (applies to all treeviews)

我想要为每个树视图标题创建自定义样式并应用它们,就像我为树视图的主体所做的那样。

标签: pythontkintertreeviewttk

解决方案


推荐阅读