Last Updated : 05 Sep, 2020
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.
InstallationInstall the package pyscreenshot using the below command in your command prompt.
pip install pyscreenshotCapturing 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
# Program to take screenshot
import pyscreenshot
# To capture the screen
image = pyscreenshot.grab()
# To display the captured screenshot
image.show()
# To save the screenshot
image.save("GeeksforGeeks.png")
Output:
Full Screenshot Capturing part of the screenHere 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
# Program for partial screenshot
import pyscreenshot
# im=pyscreenshot.grab(bbox=(x1,x2,y1,y2))
image = pyscreenshot.grab(bbox=(10, 10, 500, 500))
# To view the screenshot
image.show()
# To save the screenshot
image.save("GeeksforGeeks.png")
Output:
Partial ScreenshotImportant Points:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4