Python offers multiple libraries to ease our work. Here we will learn how to take a screenshot using Python. Python provides a module called pyscreenshot for this task. It is only a pure Python wrapper, a thin layer over existing backends. Performance and interactivity are not important for this library.
Installation
Install the package pyscreenshot using the below command in your command prompt.
pip install pyscreenshot
Capturing Full Screen
Here we will learn the simplest way of taking a screenshot using pyscreenshot module. Here we will use the function show() to view the screenshot.
Python3
import pyscreenshot
image = pyscreenshot.grab()
image.show()
image.save( "GeeksforGeeks.png" )
|
Output:

Full Screenshot
Capturing part of the screen
Here is the simple Python program to capture the part of the screen. Here we need to provide the pixel positions in the grab() function. We need to pass the coordinates in the form of a tuple.
Python3
import pyscreenshot
image = pyscreenshot.grab(bbox = ( 10 , 10 , 500 , 500 ))
image.show()
image.save( "GeeksforGeeks.png" )
|
Output:

Partial Screenshot
Important Points:
- We need to install pillow (PIL) package before installing pyscreenshot package.
- Here show() function works as print i.e. It displays the captured screenshot.
- We need to pass the coordinates in tuple.
- We can save the screenshot to a file or PIL image memory.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
05 Sep, 2020
Like Article
Save Article