Take a Screenshot using Python
Hello, internet programmer today we code to take a screenshot using python. As you know python is amazing blah blah… let’s code.
We pyscreenshot module to take screenshots using python.
Installation
pip install pyscreenshot
The pyscreenshot
module is obsolete in most cases. It was created because PIL ImageGrab module worked on Windows only, but now Linux and macOS are also supported by Pillow. There are some features in pyscreenshot
which can be useful in special cases: flexible backends, Wayland support, sometimes better performance, optional subprocessing.
The module can be used to copy the contents of the screen to a Pillow image memory using various back-ends. Replacement for the ImageGrab Module.
For handling image memory (e.g. saving to file, converting,..) please read Pillow documentation.
Code
# Follow @code_snail
import pyscreenshot as ImageGrab
import datetime
import time
time.sleep(3) # tell me why I used delay here...
im = ImageGrab.grab()
im.save("screenshot-" + str(datetime.datetime.now()) + ".png")
im.show()
Output
After executing code, image is saved in the same location where your code is saved.
Happy coding :) follow me on Instagram @code_snail
You may also like,