Taking Screenshot In Python

Taking Screenshot In Python

In this exercise, we will figure out how might one take screen captures using the Python programming language. There are various approaches to accomplish something very similar, we will examine some of them in the coming areas.

How to take screenshots using Python

Python offers different libraries to take screenshots. We'll explore a couple of these libraries today and see how you can execute the code in Python to capture your screens.

Method 1: Using pyautogui module

The pyautogui module uses the screen capture function which is answerable for taking the screen capture of the entire PC screen. And afterward the save function is used to save the screen capture caught to our gadget.

import pyautogui
im = pyautogui.screenshot()
im.save("screen1.jpg")

Assuming one needs some delay prior to taking a screen capture, the developer can use the time module and using the sleep function.

Method 2: Using pillow module

The pillow module use an ImageGrab submodule. This strategy requires a region that should be caught which infers setting the askew facilitates of the region.

Then, at that point we use the grab function which will take the region boundaries to catch the screen capture. Lastly, save the caught picture use the save function.

from PIL import ImageGrab
cordinate = (300, 300, 600, 600)
image = ImageGrab.grab(cordinate)
image.save("screen2.png")

The region captured is displayed below. We can likewise use the time module to delay the catching of the screen capture.

Conclusion

So presently you realize two techniques to catch screen captures of your PC screen. Also, yes there are different techniques just as python is an extremely progressed language. Expectation you preferred understanding it!

Did you find this article valuable?

Support Shantun Parmar by becoming a sponsor. Any amount is appreciated!