Get screenshot on Windows with Python? Get screenshot on Windows with Python? python python

Get screenshot on Windows with Python?


Another approach that is really fast is the MSS module. It is different from other solutions in the way that it uses only the ctypes standard module, so it does not require big dependencies. It is OS independant and its use is made easy:

from mss import msswith mss() as sct:    sct.shot()

And just find the screenshot.png file containing the screen shot of the first monitor. There are a lot of possibile customizations, you can play with ScreenShot objects and OpenCV/Numpy/PIL/etc..


Worth noting that ImageGrab only works on MSWindows.

For cross platform compatibility, a person may be best off with using the wxPython library.http://wiki.wxpython.org/WorkingWithImages#A_Flexible_Screen_Capture_App

import wxwx.App()  # Need to create an App instance before doing anythingscreen = wx.ScreenDC()size = screen.GetSize()bmp = wx.EmptyBitmap(size[0], size[1])mem = wx.MemoryDC(bmp)mem.Blit(0, 0, size[0], size[1], screen, 0, 0)del mem  # Release bitmapbmp.SaveFile('screenshot.png', wx.BITMAP_TYPE_PNG)


This can be done with PIL. First, install it, then you can take a full screenshot like this:

import PIL.ImageGrabim = PIL.ImageGrab.grab()im.show()