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') #正确代码如示例。书中有错误,具体原因未知

    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab