首先安装pyautogui
pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com pyautogui
下面是代码:
import pyautogui
import time
#截屏延迟
pyautogui.PAUSE = 0.5
#整个屏幕截图并保存
screenshot = pyautogui.screenshot()
screenshot.save('screenhot3.png') #screenhot.png就是你截屏的名字
screenshot = pyautogui.screenshot('screenshot32.png')
for i in range(3):
screenshot = pyautogui.screenshot()
filename = 's'+str(i)
print(filename)
screenshot.save(filename+".png")
time.sleep(1)
im = pyautogui.screenshot(region=(100, 100, 500, 500))
im.save('s-im.png') #screenhot.png就是你截屏的名字
from PIL import ImageGrab
# 取得屏幕上的一个区域
image = ImageGrab.grab(bbox=(100, 100, 500, 500))
image.show()