如何設定某些 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