当鼠标位于像素范围内时,我想更改光标的外观,当鼠标超出该范围时,它会变为正常(我不想使用画布/其他小部件“cursor=”kwarg)
from tkinter import*
root = Tk()
root.geometry('500x500+0+0')
def change_cursor(event):
if event.x in range(450,500):
#change how the cursor looks
root.bind('<B1-Motion>', change_cursor)
root.mainloop()
不幸的是,做你想做的事情的唯一方法就是使用
root.config(cursor="cursor_name")
"watch"
cursor\u name代表忙碌的光标,""
cursor\u name代表正常的光标此外,您还需要将
"<B1-Motion>"
事件(鼠标拖动,按下鼠标左键)更改为"<Motion>"
事件(鼠标移动,无需按下任何鼠标按钮)当然,您需要将光标更改回(
else
块)以下是固定代码:
相关问题 更多 >
编程相关推荐