วิดเจ็ตปุ่มใน Tkinter มีคุณสมบัติ inbuilt มากมาย ซึ่งสามารถใช้ในการกำหนดค่าและทำงานบางอย่างในแอปพลิเคชัน ในการเรียกใช้เหตุการณ์เฉพาะในแอปพลิเคชัน เราสามารถใช้ bind("
ตัวอย่าง
# Import the required libraries
from tkinter import *
from tkinter import ttk
# Create an instance of tkinter frame or window
win=Tk()
# Set the size of the window
win.geometry("700x350")
def change_bgcolor(e):
win.config(background="green3")
def change_fgcolor(e):
win.config(background="white")
# Add Buttons to trigger the event
b1=Button(win, text="Hover on Me", font=('Georgia 16'))
b1.pack(pady=60,anchor=CENTER)
# Bind the events
for b in [b1]:
b.bind("<Enter>",change_bgcolor)
b.bind("<Leave>", change_fgcolor)
win.mainloop() ผลลัพธ์
หากเราเรียกใช้โค้ดข้างต้น จะแสดงหน้าต่างที่มีปุ่ม

เมื่อเราวางเมาส์บนปุ่ม มันจะเปลี่ยนสีพื้นหลังของหน้าต่างหลัก
