I am creating a Beta Testers reporting module so they can send in thier comments on my software, but I would like to have the option to include a screenshot with the report. How do I take a screenshot of the screen with Python on Windows? I have found several examples on Linux, but haven't had much luck on Windows.
The pyautogui module makes use of the screenshot function which is responsible for taking the screenshot of the whole computer screen. And then the save function is used to save the screenshot captured to our device.
Select a code and press a hot-key (Ctrl+Alt+Shift+A by default) to copy it as the image (make a screenshot).
Take the first screenshot using Selenium WebDriver and function save_screenshot() Take a screenshot using Python selenium-screenshot – Using Screenshot_Clipping from the Screenshot module, and the full_Screenshot() function.
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 mss with 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 wx app = wx.App() # Need to create an App instance before doing anything screen = wx.ScreenDC() size = screen.GetSize() bmp = wx.Bitmap(size[0], size[1]) mem = wx.MemoryDC(bmp) mem.Blit(0, 0, size[0], size[1], screen, 0, 0) del mem # Release bitmap bmp.SaveFile('screenshot.png', wx.BITMAP_TYPE_PNG)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With