Screenshot In Python
Published on October 28 2021
In this tutorial, you will learn how to take a screenshot in Python using the pyautogui module and Pillow library. We will understand both methods in detail with examples.
pyautogui Module Installation
pip install pyautogui |
pillow Module Installation
pip install pillow |
Source code
# Method - 1 --> using pyautogui module
import pyautogui, time
time.sleep(5)
screeshot = pyautogui.screenshot()
screeshot.save('image1.png')
print('screenshot taken using pyautogui.')
# Method - 2 --> using Pillow module
from PIL import ImageGrab
image = ImageGrab.grab(bbox=(100,100,500,800))
image.save('image2.png')
print('screenshot taken using Pillow.')
Video