DEV Community

Max
Max

Posted on

How to take Screenshot using Python

We will see how to take screenshot using python in desktop with the help of pyautogui package this package is used of GUI automation.

First lets install the package by running the command

pip install pyautogui
Enter fullscreen mode Exit fullscreen mode

Take screenshot using python

To take screenshot using python in desktop, for this import the pyautogui module, this comes with many features, but in this will be using the screenshot method.

import pyautogui

screen = pyautogui.screenshot()
screen.save("my_image.png")
Enter fullscreen mode Exit fullscreen mode

This will take a screenshot of the entire screen and save it to the current working directory, to save the image in different directory change the path in save function.

Saving screenshot to folder

import pyautogui

screen = pyautogui.screenshot()
screen.save("test/image/my_image.png")
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
shadow_b profile image
shadowb

Simple and clean.