双特金特画布中的双光标

2024-07-01 08:27:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两个画布显示图像(一个是源代码,另一个稍微修改)。 我想同步两张画布的光标,即当光标悬停在一张画布上时,光标也会显示在另一张画布上的相同位置。 我已经画了一个自定义的加号光标(两条相交的线),但是我对结果不满意。 有没有办法把鼠标停在画布上的某个特定位置“伪装”出来?你知道吗

编辑: 我的相关代码,根据要求:

self.canvas_image.bind("<Motion>", self.processMouseEvent)

def processMouseEvent(self): 
     self.cursorSync.Sync(event)

Tags: 代码图像imageself编辑源代码bind画布
2条回答

不,一次不能有多个光标处于活动状态。您唯一的选择是通过在画布上绘制一个光标或使用放置在画布上的小部件来模拟第二个光标。你知道吗

Motion事件将有一个x,y属性分配给它。为什么不这样做呢,光标可以是任何可以由place几何体管理器管理的对象:

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()

相关问题 更多 >

    热门问题