Python take screenshot of specific window
In this post, you will learn how to take a screenshot of a specific window using the Python programming language.
Screen captures let you capture precisely the thing you're seeing on your screen to impart to other people or reference later. Taking, saving, and sharing screen captures can be very useful. Truth be told, some demand that screen capture be the main thing on the web.
There are various ways to capture a screen using the Python programming language. The PyAutoGUI module is the most popular. PyAutoGUI works on Windows, macOS, and Linux, and supports Python 2.x and 3.x. It is a cross-platform GUI automation Python module. This module provides many generic functions that help in performing various operations, like taking screenshots, automating GUI testing, automating tasks, and so on. It allows us to control the mouse and keyboard to perform various activities.
Install PyAutoGUI
The following command installs the PyAutoGUI module-
pip install pyautogui
Python code to take screenshot
The PyAutoGUI module provides a screenshot() method to take a screenshot.
import pyautogui
scr= pyautogui.screenshot()
myScreenshot.save(r'screenshot.png')
When we run the above code, the screenshot will be saved at the specified location.
Python code to take a screenshot with time
In the above example, we have not mentioned the time. Suppose we want to take a screenshot of some other window, so what can we do? We can use the time module and set the duration in the sleep() method to delay the execution of the program.
import pyautogui, time
time.sleep(10)
scr= pyautogui.screenshot()
myScreenshot.save(r'screenshot.png')
On run the above code, the screenshot will be saved in the specified location-
Related Articles
Python OpenCV Image Filtering
Python OpenCV Overlaying or Blending Two Images
Python OpenCV Histogram of Grayscale Image
Find the stop words in nltk Python
Install NLTK for Python on Windows 64 bit
Python Tkinter Combobox Event Binding
Python Tkinter Combobox
Simple Calculator Program in Python
Python Webbrowser
Python program to bouncing ball in Pygame
Remove last element from list Python
Check if list is empty Python
Python program to multiply two numbers
Python split multiple delimiters
Python loop through list
Python iterate list with index
calculate simple interest in Python
Python random choice
Python dict inside list
Python program to display calendar
Python raise keyword