Tkinter เป็นไลบรารี Python มาตรฐานพัฒนาแอปพลิเคชัน GUI สามารถเปลี่ยนคุณสมบัติ widgets ด้วยฟังก์ชันและเมธอดในตัว บางแอปพลิเคชัน คุณสมบัติส่งผลต่อเมาส์ด้วย
Tkinter ให้วิธีเปลี่ยนสีเคอร์เซอร์เมาส์ในหน้าต่าง ตั้งค่าสีเคอร์เซอร์ ระบุค่า cursor ด้วย (cursor type และ สี) เช่น ใน label widget ระบุ cursor="plus #aab1212" โดย "plus" คือประเภทเคอร์เซอร์ และ #aab1212 คือค่า Hex ของสี
ตัวอย่าง
# Import the required libraries
from tkinter import *
# Create an instance of tkinter frame or window
win=Tk()
# Set the size of the window
win.geometry("700x350")
# Add bottom widget
label=Label(win, text="label cursor", cursor="plus red", font=('calibri 18'))
label.pack(pady=20)
Button(win, text="Button cursor", cursor="dot blue").pack()
win.mainloop()
ผลลัพธ์
รันโค้ด จะแสดงหน้าต่างพร้อม label widget และปุ่ม Hover บน widget จะเปลี่ยนคุณสมบัติเคอร์เซอร์
