看起来 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')