สมมติว่าเราต้องการเปลี่ยนสีขอบของวิดเจ็ต tkinter เราสามารถกำหนดค่าวิดเจ็ตโดยส่ง สีไฮไลท์ พื้นหลังไฮไลต์ คุณสมบัติของวิดเจ็ต
ตัวอย่าง
ในตัวอย่างนี้ เราได้สร้างวิดเจ็ตรายการและปุ่มที่สามารถเรียกใช้เพื่อเปลี่ยนสีเส้นขอบของวิดเจ็ตรายการได้
#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() ผลลัพธ์
การเรียกใช้โค้ดด้านบนจะแสดงหน้าต่างที่มีปุ่มซึ่งสามารถใช้เปลี่ยนสีขอบของวิดเจ็ตรายการได้

ตอนนี้คลิกที่ปุ่ม "เปลี่ยน" เพื่อเปลี่ยนสีเส้นขอบของวิดเจ็ต
