python tkinter treeview制作_python-3.x – Tkinter Treeview标题样式

我想更改树视图标题的背景颜色.我已经确定了Treeview.Heading布局的元素选项,负责这个:Treeheading.cell.问题是这个设置不适用于’vista’主题(由于我假设的绘图问题).

工作代码(虽然主题看起来很可怕):

from tkinter import *

from tkinter import ttk

p=Tk()

separator = PanedWindow(p,bd=0,bg="#202322",sashwidth=2)

separator.pack(fill=BOTH, expand=1)

_frame = Frame(p,bg="#383838")

t=ttk.Treeview(_frame)

t["columns"]=("first","second")

t.column("first",anchor="center" )

t.column("second")

t.heading("first",text="first column")

t.heading("second",text="second column")

t.insert("",0,"dir1",text="directory 1")

t.insert("dir1","end","dir 1",text="file 1 1",values=("file 1 A","file 1 B"))

id=t.insert("","end","dir2",text="directory 2")

t.insert("dir2","end",text="dir 2",values=("file 2 A","file 2 B"))

t.insert(id,"end",text="dir 3",values=("val 1 ","val 2"))

t.insert("",0,text="first line",values=("first line 1","first line 2"))

t.tag_configure("ttk",foreground="black")

ysb = ttk.Scrollbar(orient=VERTICAL, command= t.yview)

xsb = ttk.Scrollbar(orient=HORIZONTAL, command= t.xview)

t['yscroll'] = ysb.set

t['xscroll'] = xsb.set

print(ttk.Style().theme_names())

ttk.Style().theme_use('default')

ttk.Style().configure("Treeview", background="#383838",foreground="white")

ttk.Style().configure("Treeview.Heading",background = "blue",foreground="Black")

p.configure(background='black')

t.grid(in_=_frame, row=0, column=0, sticky=NSEW)

ysb.grid(in_=_frame, row=0, column=1, sticky=NS)

xsb.grid(in_=_frame, row=1, column=0, sticky=EW)

_frame.rowconfigure(0, weight=1)

_frame.columnconfigure(0, weight=1)

separator.add(_frame)

w = Text(separator)

separator.add(w)

p.mainloop()

我尝试使用’vista’主题:

ttk.Style().element_create("Treeheading.cell","from","default")

ttk.Style().configure("Treeview", background="#383838",foreground="white")

ttk.Style().configure("Treeview.Heading",background = "Blue")

element_create在此问题的其他实例中工作但具有不同的小部件.

谢谢,任何帮助将不胜感激.

在python 3中工作.此外,代码不是我的,我发现它并用它来测试.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值