Python 如何设置某些 Tkinter 小部件的边框颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4320725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set border color of certain Tkinter widgets?
提问by Jeff
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 小部件的边框颜色?
采纳答案by Jeff
Just use
只需使用
widget.config(highlightbackground=COLOR)
Furthermore, if you don't want that border at all, set the highlightthicknessattribute to 0 (zero).
此外,如果您根本不需要该边框,请将highlightthickness属性设置为 0(零)。
回答by Utopion
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()

