Python의 tkinter 8.5에서 ttk.LabelFrame의 파란색 헤더 레이블을 검정색으로 어떻게 변경합니까?

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

  •  20-12-2019
  •  | 
  •  

문제

저는 Windows 7 컴퓨터에서 tkinter 8.5와 Python 3.3을 사용하고 있습니다.

아래 코드는 Labelframe의 헤더를 파란색 글꼴 색상으로 렌더링합니다.

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()을 추가하여 이 문제를 해결하려고 시도했지만 예상치 못한 화면이 표시되었습니다.

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 헤더를 검은색으로 표시하는 방법이 있습니까?

도움이 되었습니까?

해결책

Windows의 기본값은이 푸른 색으로 ttk.labelframe 헤더를 기본값으로 기본 설정합니다.이유를 모르겠습니다.

Mac 및 Linux는 Black에서 Black으로 기본값으로 기본값으로 표시됩니다.

ttk.label을 만들고 ttk.labelframe의 labelwidget 인수로 전달하여 솔루션을 찾았습니다.그러나 이것은 더 많은 해결책 일 수 있습니다.어떤 경우에도 아래 코드는 내 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()
.

다른 팁

전경 속성 tk.LabelFrame(window, foreground='red')

를 사용하여 변경할 수도 있습니다.

그냥 제거하면됩니다 style='TLabelframe.Label' ~로부터 ttk.LabelFrame 옵션.

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

저는 Python 3.7.3과 tkinter 8.6을 사용하고 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top