微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Tkinter 树视图样式

如何解决Tkinter 树视图样式

为什么我的表格没有根据我定义的样式改变样式? 我尝试使用样式和地图,但没有任何改变。 似乎唯一有效的是主题配置。 滚动条也不显示在树视图中。

from tkinter import *
from tkinter import ttk

class Dashboard:

def __init__(self,filterdDf):

    self.filterdDf = filterdDf

    root =Tk()
    root.title('Dashboard')
    root.geometry('1300x690')
    root.resizable(False,False)

    frame = Frame(root,width=1100,height=690)
    frame.configure(background="gray28")
    frame.pack(fill=BOTH,expand=True)

    rows = len(filterdDf)

    tree = ttk.Treeview(root,columns=(1,2),height=rows,show="headings")
    tree.pack(side='left')
    tree.place(x=700,y=150)

    #Add some style:
    style = ttk.Style()

    style.theme_use("clam")

    style.configure("Treeview",background="silver",foreground="black",rowheight=55,fieldbackground="silver")

    #Change selected color:
    style.map("Treeview",background=[('selected','green')])

    tree.heading("#0",text="Label",anchor=W)
    tree.heading("#1",text="Approach",anchor=CENTER)
    tree.heading("#2",text="Recommendation",anchor=CENTER)

    tree.column("#0",width=120,minwidth=25)
    tree.column("#1",width=300,minwidth=25,anchor=W)
    tree.column("#2",width=150,anchor=CENTER)

    scroll = ttk.Scrollbar(frame,orient="vertical",command=tree.yview)
    scroll.pack(side='right',fill='y')

    tree.configure(yscrollcommand=scroll.set)

    for i in range(rows):
        tree.insert(parent='',index='end',values=(filterdDf[('Approaches','All')].iloc[i],filterdDf[('Recommendation Level','')].iloc[i]))

    root.mainloop()

这是我的 Treeview 的样子: 2 列填充数据。 谢谢!

enter image description here

这是样式配置的外观(不同的数据但相同的配置):

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。