¿Cómo cambio la etiqueta de encabezado azul de ttk.LabelFrame a negra en tkinter 8.5 de Python?

StackOverflow https://stackoverflow.com//questions/25002373

  •  20-12-2019
  •  | 
  •  

Pregunta

Estoy usando tkinter 8.5 y python 3.3 en una máquina con Windows 7.

El siguiente código muestra el encabezado del Labelframe en un color de fuente azul.

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

Intenté solucionar esto agregando ttk.Style(), pero obtuve una visualización inesperada:

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

¿Hay alguna manera de hacer que un encabezado ttk.LabelFrame aparezca en color negro sin efectos secundarios extraños?

¿Fue útil?

Solución

Parece que Windows predeterma los encabezados TTK.LABELFRAME a este color azul.No estoy seguro de por qué.

Mac y Linux predeterminado a Black, mientras que Windows predeterminado a Blue

Encontré una solución creando un ttk.label y pasando el argumento de Labelwidget de TTK.Labelframram.Sin embargo, esto podría ser más de una solución.En cualquier caso, el código a continuación muestra el texto del encabezado en negro en mi máquina de Windows 7.

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

Otros consejos

Esto también se puede cambiar usando la propiedad de primer plano. tk.LabelFrame(window, foreground='red')

Sólo necesitas quitar el style='TLabelframe.Label' desde el ttk.LabelFrame opciones.

import tkinter as tk
from tkinter import ttk

root = tk.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.")
lf.pack()

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

Estoy usando Python 3.7.3 y tkinter 8.6.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top