hebeer 2019-09-24 16:24 采纳率: 0%
浏览 491

鼠标拖动报错,一直在网上找不到答案,求大神支招

按照书上描述麻了如下代码,居然报错了,报错了,报错了。一直百度不得其解,故上来问问大神
系统是osX,该下的模块以及依赖包都下好,就是有问题。
代码如下:

import pyautogui, time
time.sleep(5)
pyautogui.click()
distance = 200
while distance >0:
    pyautogui.dragRel(distance, 0, duration=0.2)
    distance = distance - 5
    pyautogui.dragRel(0, distance, duration=0.2)
    pyautogui.dragRel(-distance, 0, duration=0.2)
    distance = distance - 5
    pyautogui.dragRel(0, -distance, duration=0.2)


报错如下

Traceback (most recent call last):
  File "/Users/jibohe/exercise.py", line 11, in <module>
    pyautogui.dragRel(distance,0,duration=0.2)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyautogui/__init__.py", line 944, in dragRel
    _mouseMoveDrag('drag', mousex, mousey, xOffset, yOffset, duration, tween, button)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyautogui/__init__.py", line 1053, in _mouseMoveDrag
    platformModule._dragTo(tweenX, tweenY, button)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyautogui/_pyautogui_osx.py", line 436, in _dragTo
    assert False, "button argument not in ('left', 'middle', 'right')"
AssertionError: button argument not in ('left', 'middle', 'right')
  • 写回答

2条回答 默认 最新

  • weixin_51485773 2020-11-28 23:29
    关注

    pyautogui.dragRel(distance, 0, duration=0.2,button='left') #正确代码如示例。书中有错误,具体原因未知

    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型