tkinter 更改样式问题 [英] tkinter change style questions

查看:35
本文介绍了tkinter 更改样式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我有这个代码:

tree = ttk.Treeview(root)
style = ttk.Style()
style.configure("Treeview", foreground='#00337f',background="#ffc61e")
style.configure("Treeview.Heading", background="purple",foreground='#00337f',font=(20))
tree["columns"] = ("one", "two", "three")
tree.column("one", width=150)
tree.column("two", width=150)
tree.column("three", width=210)
tree.heading("one", text="Naar")
tree.heading("two", text="Spoor")
tree.heading("three", text="Vetrektijd")
tree.tag_configure('monospace', font=20)
tree['show'] = 'headings'
tree.place(x=0, y=0)

除了 3 件事外,一切正常:

Everything works fine except 3 things:

  • 每当我运行程序时,树视图背景仍然是白色的,但从一开始就必须是黄色的.现在每当树视图被填充时它就会变成黄色.

  • Whenever I run the program the treeview background is still white but it needs to be yellow from the beginning. Right now it becomes yellow whenever the treeview is filled.

第二个问题是我将标题的背景更改为紫色,正如您在上面的代码中看到的那样,但它仍然是白色的.那么我怎样才能让它变成紫色?

The second problem is that I changed the background of the heading to purple as you can see in the code above but it still is white. So how can I make it purple?

第三个问题是treeview填充后还有一行:

The third problem is there is still a line after the treeview is filled:

推荐答案

第一个问题可以通过在Treeviewfieldbackground="#ffc61e"解决> 风格.背景选项仅对应于项目的背景.但是,并非所有主题都考虑了 fieldbackground 选项(请参阅第二个问题).

The first problem can be solved by adding fieldbackground="#ffc61e" in the configuration of the Treeview style. The background option corresponds to the background of the items only. However, not all themes takes the fieldbackground option into account (see the second problem).

第二个问题是主题相关的.您使用的主题不支持标题的颜色更改,因此我建议您使用另一种,例如 'clam' 或 'alt':style.theme_use('clam').

The second problem is theme related. The theme you are using does not support color change for the headings, so I suggest you to use another one like 'clam' or 'alt': style.theme_use('clam').

要去除标题中按钮的边框,可以将边框宽度设置为0:style.configure("Treeview.Heading", borderwidth=0).

To remove the borders of the buttons in the heading, you can set the border width to 0: style.configure("Treeview.Heading", borderwidth=0).

不幸的是,这对Treeview边框不起作用,因此解决方法是将边框的所有颜色设置为背景色:

Unfortunately, this does not work for the Treeview border, so the solution is to set all colors of the border to the background color:

style.configure("Treeview", lightcolor="#ffc61e", bordercolor="#ffc61e",
                darkcolor="#ffc61e")

这篇关于tkinter 更改样式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆