2

我正在尝试使用pyautogui模块截取屏幕截图,但不断收到此错误

>>> image = pyautogui.screenshot()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'pyautogui' has no attribute 'screenshot'

有什么我想念的吗?Automate the Boring Stuff with Python一章说,因为我在 Windows 上,所以我不需要下载任何东西pyautogui就可以了。有谁知道为什么会发生这种情况?提前致谢。

编辑:我正在使用 Anaconda,所以我已经有了Pillow.

4

4 回答 4

0
from pyautogui import screenshotUtil

im=screenshotUtil.screenshot()

print im.getpixel((850, 850))

我努力了。它似乎与文档不同。希望这是有帮助的。

于 2017-07-25T07:43:43.687 回答
0

看起来 PyAutoGUI 只是从 PIL/Pillow 借用 ImageGrab,您可以通过查看 screenshotUtil.py 中的 pyautogui 来看到

def _screenshot_win32(imageFilename=None):
    im = ImageGrab.grab()
    if imageFilename is not None:
        im.save(imageFilename)
    return im

再往下

# set the screenshot() function based on the platform running this module
if sys.platform.startswith('java'):
    raise NotImplementedError('Jython is not yet supported by PyAutoGUI.')
elif sys.platform == 'darwin':
    screenshot = _screenshot_osx
elif sys.platform == 'win32':
    screenshot = _screenshot_win32
    from PIL import ImageGrab
else:
    screenshot = _screenshot_linux

grab = screenshot # for compatibility with Pillow/PIL's ImageGrab module.

我遇到了和 OP 一样的麻烦,但是在意识到上述之后我直接使用了 ImageGrab。从这里的评论部分中汲取灵感,安装枕头的窗户上的 OP 答案如下所示:

from PIL import ImageGrab
import time

time.sleep(5)
box = (1106,657,1166,679) #Upper left and lower right corners
ImageGrab.grab(box).save('box.png') #ImageGrab.grab().save('fullscreen.png')
于 2017-03-08T15:26:52.017 回答
0

在 Linux 上,您必须运行sudo apt-get install scrot才能使用屏幕截图功能。

于 2016-08-22T12:51:47.710 回答
-1

在使用“image = pyautogui.screenshot()”之前,您必须先输入“import pyautogui”

于 2016-08-22T12:46:35.410 回答