如何设置某些 Tkinter 控件的边框颜色?
我们假设想要更改 Tkinter 控件的边框颜色。我们可以通过传递控件的 highlightcolor, highlightbackground 属性来配置控件。
示例
在此示例中,我们创建了一个 Entry 控件和一个按钮,可以触发以更改 Entry 控件的边框颜色。
#Import the required libraries
from tkinter import *
#Create an instance of tkinter frame
win= Tk()
#Set the geometry of frame
win.geometry("600x250")
#Define a function to change the color of entry widget
def change_color():
text.config(highlightthickness=2, highlightbackground="red")
#Create a Entry widget for which we want to change the border color
text= Entry(win, width= 50)
text.pack()
#Create a Button Widget
button= Button(win, text= "Change", command=change_color)
button.pack(pady=20)
win.mainloop()输出
运行以上代码将显示一个窗口,其中包含一个按钮,可用于更改输入控件的边框颜色。

现在单击“更改”按钮来更改控件的边框颜色。

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP