python鼠标移动怎么写_绘制鼠标移动Python

我想使用matplotlib和pynput近乎实时地绘制鼠标的移动,但我怀疑我遇到了一些被阻止的代码问题.代码使用的是

this answer的简化版本.

import matplotlib.pyplot as plt

from pynput import mouse

from time import sleep

fig, ax = plt.subplots()

ax.set_xlim(0, 1920-1)

ax.set_ylim(0, 1080-1)

plt.show(False)

plt.draw()

x,y = [0,0]

points = ax.plot(x, y, 'o')[0]

# cache the background

background = fig.canvas.copy_from_bbox(ax.bbox)

def on_move(x, y):

points.set_data(x,y)

# restore background

fig.canvas.restore_region(background)

# redraw just the points

ax.draw_artist(points)

# fill in the axes rectangle

fig.canvas.blit(ax.bbox)

with mouse.Listener(on_move=on_move) as listener:

sleep(10)

代码似乎停在ax.draw_artist(点)上. pynput鼠标侦听器是一个threading.Thread,并且所有回调都是从线程调用的.我对matplotlib或线程的内部工作原理不太熟悉,无法确定原因.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值