Reputation:
I want the cursor to be an image when hovering over my canvas, when i run this it gives me 'bad cursor spec "pyimage1"' error. Is it possible?
from tkinter import*
root = Tk()
root.geometry('500x500+0+0')
custom_cursor = PhotoImage(file='custom_cursor.png')
canvas = Canvas(root, height=50, width=50, bg='black', cursor=custom_cursor)
canvas.pack()
root.mainloop()
Upvotes: 0
Views: 1700
Reputation: 385830
No, it is not possible to use an image as a cursor. At least, not directly. The cursor
option must be one of the following:
The definitive description of the cursor
option is on the tcl/tk man page for Tk_GetCursor
Since you are using a canvas, you can simulate a cursor with an image by drawing a normal image and updating it's position whenever the cursor moves, though it would lag very slightly being the real cursor.
Upvotes: 1