简体   繁体   English

Tkinter。 如何更改LabelFrame标题的背景颜色?

[英]Tkinter. How to change the background color of LabelFrame title?

I need to set a white background color of the LabelFrame title. 我需要设置LabelFrame标题的白色背景色。 I'm working on Tkinter in Python 3.6 我正在使用Python 3.6进行Tkinter

Capture 捕获

You can specify your own widget to use as the LabelFrame 's "label" — this mean, for example, you could create a separate Label widget with the text attributes you want, and specify it when creating the LabelFrame via the labelwidget= option: 您可以指定自己的窗口小部件用作LabelFrame的“标签”,例如,这意味着您可以使用所需的文本属性创建一个单独的Label小部件,并在通过labelwidget=选项创建LabelFrame时指定它:

import tkinter as tk

root = tk.Tk()
root.geometry('300x75')

label = tk.Label(root, text='Life, the universe and everything?', fg='white',
                 bg='blue')
lable_frame = tk.LabelFrame(root, labelwidget=label)  # Use custom label.
lable_frame.pack(fill=tk.BOTH, expand=1, padx=5, pady=5)

w = tk.Entry(lable_frame)
w.pack(side=tk.LEFT, fill=tk.X, expand=1)

root.mainloop()

Result: 结果:

屏幕截图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM