Open In App

Taking Screenshots using pyscreenshot in Python

Last Updated : 05 Sep, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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




# 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 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




# 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 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.


Previous Article
Next Article

Similar Reads

How to take screenshots using python?
Python is a widely used general-purpose language. It allows performing a variety of tasks. One of them can be taking a screenshot. It provides a module named pyautogui which can be used to take the screenshot. pyautogui takes pictures as a PIL(python image library) which supports opening, manipulating, and saving many different image file formats.
1 min read
Take Screenshots at Random Intervals with Python
In this article, we will learn how to take screenshots at Random Intervals with Python. Method 1: Using pyautogui.screenshot() pyautogui: The pyautogui library provides the screenshot() method, The screenshot() method is used to take a screenshot. We will use the random library and sleep() method to take screenshots at Random Intervals. Syntax: pya
5 min read
Taking input from console in Python
What is Console in Python? Console (also called Shell) is basically a command line interpreter that takes input from the user i.e one command at a time and interprets it. If it is error free then it runs the command and gives required output otherwise shows the error message. A Python Console looks like this. Here we write a command and to execute
2 min read
Python VLC MediaPlayer – Taking Screenshot
In this article we will see how we can take screen shot of the MediaPlayer object in the python vlc module. VLC media player is a free and open-source portable cross-platform media player software and streaming media server developed by the VideoLAN project. MediPlyer object is the basic object in vlc module for playing the video. A screenshot, als
2 min read
Taking multiple inputs from user in Python
The developer often wants a user to enter multiple values or inputs in one line. In C++/C user can take multiple inputs in one line using scanf but in Python user can take multiple values or inputs in one line by two methods.  Methods to Take multiple inputs from user Using split() method :Using map() with split():Using List comprehension : Using s
4 min read
Taking input in Python
Developers often have a need to interact with users, either to get data or to provide some sort of result. Most programs today use a dialog box as a way of asking the user to provide some type of input. While Python provides us with two inbuilt functions to read the input from the keyboard.   input ( prompt )raw_input ( prompt )input (): This funct
4 min read
Transform string str1 into str2 by taking characters from string str3
Given three strings str1, str2 & str3. The task is to find whether string str1 can be transformed to string str2 by taking characters from str3. If yes then print “YES”, Else print “NO”.Examples: Input: str1 = "abyzf", str2 = "abgdeyzf", str3 = "poqgode". Output: YES Explanation: Remove 'g' from str3 and insert it after 'b' in str1, A = "abgyzf
9 min read
Taking password as input in C++
There are two methods in which input can be taken in a more secure way: Do not display any content.Display a special character such as an asterisk instead of actual content. In this method, input content will be invisible. This can be implemented in two ways: using <windows.h>: Program 1: Below is the program where console mode is set to enab
4 min read
Python | Create video using multiple images using OpenCV
As we know OpenCV is a widely used library for image processing. It provides a wide sense of image processing. Let's see how to create video using multiple images using OpenCV. Install the following libraries: PIL cv2 Also, check the path before running the code otherwise you will be full with errors. How it works ? Using PIL library we are opening
3 min read
Python | Create a stopwatch using clock object in kivy using .kv file
Kivy is a platform-independent GUI tool in Python. As it can be run on Android, IOS, Linux and Windows, etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktop applications. Kivy Tutorial - Learn Kivy with Examples. Clock Object: The Clock object allows you to schedule a function call in
6 min read
Practice Tags :