繁体   English   中英

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

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

我正在尝试更改我的 Tkinter 应用程序的背景颜色,但对于某些小部件,它会在边缘周围留下白色边框。

例如,这个:

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

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

只需使用

widget.config(highlightbackground=COLOR)

此外,如果您根本不需要该边框,请将highlightthickness属性设置为 0(零)。

您必须将两个高光(有焦点和无焦点)设置为连续颜色。

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