Tkinter มีคุณสมบัติและคุณลักษณะในตัวมากมายที่ช่วยให้นักพัฒนาแอปพลิเคชันสร้างแอปพลิเคชันที่มีประสิทธิภาพและโดดเด่น เราสามารถตั้งค่าแอตทริบิวต์ต่างๆ เช่น สีพื้นหลัง สีพื้นหน้า และคุณสมบัติอื่นๆ ของวิดเจ็ตโดยใช้วิธีกำหนดค่าใน Tkinter
ในการตั้งค่าสีพื้นหลังหรือสีพื้นหน้าของวิดเจ็ต เราสามารถใช้ทั้งรหัสสีเริ่มต้นและ RGB RGB ถูกกำหนดโดยอักขระที่เป็นตัวอักษรและตัวเลขคละกัน 6 หลักที่มีค่า R, G, B ต่างกัน ในการใช้รหัสสี RGB ใน tkinter เราต้องกำหนดโดยใช้รูปแบบ #aab123
ตัวอย่าง
# Import the required libraries
from tkinter import *
from tkinter import ttk
# Create an instance of tkinter frame
win = Tk()
# Set the size of the tkinter window
win.geometry("700x350")
# Configure the color of the window
win.configure(bg='#65A8E1')
# Define the style for combobox widget
style = ttk.Style()
style.theme_use('xpnative')
# Define an event to close the window
def close_win(e):
win.destroy()
# Add a label widget
label = ttk.Label(win, text="Eat, Sleep, Code and Repeat", font=('Times New Roman italic', 22), background="black", foreground="white")
label.place(relx=.5, rely=.5, anchor=CENTER)
win.mainloop() ผลลัพธ์
การรันโค้ดด้านบนจะแสดงหน้าต่างที่มีสีพื้นหลังที่กำหนดเอง

ตอนนี้ ให้หารหัสสีใหม่เพื่อเปลี่ยนสีพื้นหลังของหน้าต่าง