[英]Python tkinter how can I set the cursor as an image
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.当我将鼠标悬停在我的 canvas 上时,我希望 cursor 成为图像,当我运行它时,它给了我“糟糕的 cursor 规范“pyimage1”错误。 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()
No, it is not possible to use an image as a cursor.不可以,不能将图像用作 cursor。 At least, not directly.
至少,不是直接的。 The
cursor
option must be one of the following: cursor
选项必须是以下选项之一:
The definitive description of the cursor
option is on the tcl/tk man page for Tk_GetCursor cursor
选项的最终描述在Tk_GetCursor的 tcl/tk 手册页上
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. 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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.