Python take screenshot of specific window
In this post, you will learn how to take screenshot of specific window using Python programming.
Screen captures let you catch 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 the screen capture is the main thing on the web.
There are various ways to capture screen in Python. The PyAutoGUI module is most popular. It is a cross-platform GUI automation Python module. It allows us to control mouse and keyboard to perform various activities.
The following command installs the PyAutoGUI module -
pip install pyautogui
Python code to take screenshot
The PyAutoGUI module provides 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 screenshot with time
In the above example, we have not mentioned the time. Suppose, we want to take screenshot of some other window, so what we can do? We can use the time module and set the duration in 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 -
Convert list to dictionary Python
Convert array to list Python
numpy dot product
glob in Python
Python heap implementation
zip function in Python
Remove last element from list Python
Check if list is empty Python
Remove element from list Python
Python split multiple delimiters
Python loop through list
Python iterate list with index
Python add list to list
Python random choice
Python dict inside list
Remove character from string Python
Python raise keyword