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,

Support CodeSnail

If you appreciate my work, or if it has helped you along your journey. It would mean a lot to me if you could write a message on my wall and share a cup of coffee (or tea) with me.

Buy Me A Coffee

Related Articles

Leave a Comment

Copy link
Powered by Social Snap