[英]How to fix PyAutoGUI AttributeError
I Have been trying to get PyAutoGUI to click one of the applications at the bottom of my screen using a very simple code.我一直在尝试让 PyAutoGUI 使用非常简单的代码单击屏幕底部的一个应用程序。 However, whenever I try to run this code I get an error that I believe is from the PyAutoGUI module I am using.但是,每当我尝试运行此代码时,我都会收到一个错误,我认为该错误来自我正在使用的 PyAutoGUI 模块。 The code is:代码是:
import pyautogui as pag
pag.click(500, 1100)
The error is:错误是:
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/pyautogui/__init__.py", line 588, in wrapper
returnVal = wrappedFunction(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/pyautogui/__init__.py", line 978, in click
platformModule._multiClick(x, y, button, clicks)
File "/usr/local/lib/python3.7/site-packages/pyautogui/_pyautogui_osx.py", line 516, in _multiClick
core_graphics.CGEventPost(kCGEvent.Tap.value, mouseEvent)
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/enum.py", line 349, in __getattr__
raise AttributeError(name) from None
AttributeError: Tap
any ideas how to fix this?任何想法如何解决这一问题?
Okay so I figured it out.好的,所以我想通了。 There is another command in the pyautogui module called pyautogui.mouseDown() and pyautogui.mouseUp(). pyautogui 模块中有另一个命令,称为 pyautogui.mouseDown() 和 pyautogui.mouseUp()。 If you uses these commands in sequence instead of pyautogui.click() it should work.如果您按顺序使用这些命令而不是 pyautogui.click() 它应该可以工作。
The working code:工作代码:
import pyautogui as pag
pag.mouseDown(500, 1100, button='left')
pag.mouseUp(500, 1100, button='left')
I'm the creator of PyAutoGUI.我是 PyAutoGUI 的创建者。 This error happened for a few versions when we were changing the dependencies for macOS.当我们更改 macOS 的依赖项时,此错误发生在几个版本中。 This has been fixed in later versions of PyAutoGUI, so just run pip3 install -U pyautogui
这已在更高版本的 PyAutoGUI 中修复,因此只需运行pip3 install -U pyautogui
Try This试试这个
import pyautogui
pyautogui.moveTo(500, 1100, duration=1)
pyautogui.click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.