In this article we use Pyscreenshot to take a screenshot using python
Pyscreenshot tries to allow to take screenshots without installing 3rd party libraries. It is cross-platform. It is only a pure Python wrapper, a thin layer over existing back-ends.
You need to install the pillow package before installing pyscreenshot package.
Installation
pip install Pillow pyscreenshot
Code
This is the easiest way of taking a screenshot using the pyscreenshot module.
The show() function displays the captured screenshot.
"Grab the whole screen" import pyscreenshot as ImageGrab # grab fullscreen im = ImageGrab.grab() # save image file im.save("fullscreen.png")
This will get a portion of the screen
You pass the coordinates in the form of a tuple to the grab function.
import pyscreenshot as ImageGrab if __name__ == '__main__': # grab fullscreen im = ImageGrab.grab(bbox=(100, 100, 800, 800)) # save file im.save('screenshot1.png') # show image in default app im.show()
Links
https://github.com/ponty/pyscreenshot