如何在 python 的 tkinter 8.5 中将 ttk.LabelFrame 的蓝色标题标签更改为黑色 [英] How do I change ttk.LabelFrame's blue header label to black in python's tkinter 8.5

查看:35
本文介绍了如何在 python 的 tkinter 8.5 中将 ttk.LabelFrame 的蓝色标题标签更改为黑色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 7 机器上使用 tkinter 8.5 和 python 3.3.

I'm using tkinter 8.5 and python 3.3 on a Windows 7 machine.

下面的代码以蓝色字体颜色呈现 Labelframe 的标题.

The code below renders the Labelframe's header in a blue font color.

from tkinter import *
from tkinter import ttk

root = Tk()

lf = ttk.LabelFrame(root, text="Why is this blue?")
lf.pack()

label = ttk.Label(lf, text="label")
label.pack()

我尝试通过添加 ttk.Style() 来解决此问题,但出现意外显示:

I tried fixing this by adding a ttk.Style(), but got an unexpected display:

from tkinter import *
from tkinter import ttk

root = Tk()

s = ttk.Style()
s.configure('TLabelframe.Label', font='arial 14 bold')

lf = ttk.LabelFrame(root, text="Now it's black, but w/ a bizarre display"
                    " and no etched frame.", style='TLabelframe.Label')
lf.pack()

label = ttk.Label(lf, text="label")
label.pack()

有没有办法让 ttk.LabelFrame 标头显示为黑色而没有奇怪的副作用?

Is there a way to get a ttk.LabelFrame header to appear black in color w/o weird side effects?

推荐答案

Windows 似乎默认 ttk.Labelframe 标头为这种蓝色.不知道为什么.

It appears that Windows defaults ttk.Labelframe headers to this blue color. Not sure why.

我通过创建 ttk.Label 并将其作为 ttk.Labelframe 的 labelwidget 参数传递找到了解决方案.不过,这可能更像是一种解决方法.无论如何,下面的代码在我的 Windows 7 机器上以黑色显示标题文本.

I found a solution by creating a ttk.Label and passing that as ttk.Labelframe's labelwidget argument. This might be more of a workaround, though. In any event, the code below displays the header text in black on my Windows 7 machine.

from tkinter import *
from tkinter import ttk

root = Tk()

l = ttk.Label(text="Not blue anymore")

lf = ttk.Labelframe(root, labelwidget=l)
lf.pack()

label = ttk.Label(lf, text="label")
label.pack()

root.mainloop()

这篇关于如何在 python 的 tkinter 8.5 中将 ttk.LabelFrame 的蓝色标题标签更改为黑色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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