简体   繁体   English

如何设置某些 Tkinter 小部件的边框颜色?

[英]How to set border color of certain Tkinter widgets?

I'm trying to change the background color of my Tkinter app, but for certain widgets it leaves a white border around the edges.我正在尝试更改我的 Tkinter 应用程序的背景颜色,但对于某些小部件,它会在边缘周围留下白色边框。

For example, this:例如,这个:

from tkinter import *

COLOR = "black"

root = Tk()
root.config(bg=COLOR)

button = Button(text="button", bg=COLOR)
button.pack(padx=5, pady=5)
entry = Entry(bg=COLOR, fg='white')
entry.pack(padx=5, pady=5)
text = Text(bg=COLOR, fg='white')
text.pack(padx=5, pady=5)

root.mainloop()

How can I set border colour of certain Tkinter widgets?如何设置某些 Tkinter 小部件的边框颜色?

Just use只需使用

widget.config(highlightbackground=COLOR)

Furthermore, if you don't want that border at all, set the highlightthickness attribute to 0 (zero).此外,如果您根本不需要该边框,请将highlightthickness属性设置为 0(零)。

You have to set the two highlights (with and without focus) to have a continuous color.您必须将两个高光(有焦点和无焦点)设置为连续颜色。

from tkinter import *
root = Tk()
e = Entry(highlightthickness=2)
e.config(highlightbackground = "red", highlightcolor= "red")
e.pack()
root.mainloop()

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

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