擅长:python、mysql、java
<p><code>Motion</code>事件将有一个x,y属性分配给它。为什么不这样做呢,光标可以是任何可以由<code>place</code>几何体管理器管理的对象:</p>
<pre><code>def move_cursor(event):
cursor.place(x=event.x, y=event.y) # set x,y to cursor
root = Tk()
left = Canvas(root, width=100, height=100, bg='white')
right = Canvas(root, width=100, height=100, bg='black')
left.pack(fill=BOTH, expand=1, side=LEFT)
right.pack(fill=BOTH, expand=1, side=RIGHT)
cursor = Label(right, width=2, bg='red') # create cursor. this could be an image or whatever
left.bind('<Motion>', move_cursor)
mainloop()
</code></pre>