且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 python 的 tkinter 8.5 中将 ttk.LabelFrame 的蓝色标题标签更改为黑色

更新时间:2023-01-26 19:05:22

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()