PIL and Python27 - Save a screengrab?
Question: Here is the code

    
    
    from PIL import ImageGrab
    scrgrb = ImageGrab.grabclipboard()
    scrgrbnum = 0
    
    def saveimg():
        scrgrb.save("screengrab.jpeg + str(scrgrbnum + 1)", "JPEG")
        scrgrbnum = scrgrbnum + 1
    
    saveimg()
    

And I get this error

    
    
    Traceback (most recent call last):   File
     "C:/Python27/Programs/screengrab", line 10, in <module>
         saveimg()   File "C:/Python27/Programs/screengrab", line 7, in saveimg
         scrgrb.save("screengrab.jpeg + str(scrgrbnum + 1)", "JPEG") AttributeError: 'NoneType' object has no attribute 'save'
    

Why can't I save a screengrab object?


Answer: try

    
    
     import win32api, win32con, ImageGrab
     win32api.keybd_event(win32con.VK_SNAPSHOT, 1)
     im = ImageGrab.grabclipboard()
     im.save("screenshot.jpg", "JPEG")
    

I think the key here is importing the winapi too.

[Source](http://traviscrowder.com/web/python-windows-print-screen-save)

