.save() is an attribute of image. You need to save like:

from PIL import ImageGrab, Image

m1 = ImageGrab.grabclipboard()
m1.save('test_image.png')
Answer from Stephen Rauch on Stack Overflow
🌐
Pillow Documentation
pillow.readthedocs.io › en › stable › reference › ImageGrab.html
ImageGrab module - Pillow (PIL Fork) 12.2.0 documentation
The ImageGrab module can be used to copy the contents of the screen or the clipboard to a PIL image memory.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-pil-imagegrab-grab-method
Python PIL | ImageGrab.grab() method - GeeksforGeeks
May 3, 2022 - Syntax: PIL.ImageGrab.grab(bbox=None) parameters: bbox: What region to copy. Default is the entire screen.
🌐
TutorialsPoint
tutorialspoint.com › python_pillow › python_pillow_imagegrab_grab_function.htm
Python Pillow - ImageGrab.grab()Function
The ImageGrab module in the Pillow library provides functionality to capture the contents of the screen or the clipboard and store it as a PIL image in memory. The ImageGrab.grab() function is used to capture a screen snapshot.
🌐
Bitbucket
hhsprings.bitbucket.io › docs › programming › examples › python › PIL › ImageGrab.html
ImageGrab Module (macOS and Windows only) — Pillow (PIL) examples
Update Pillow. img = ImageGrab.grabclipboard() if img and not isinstance(img, (list, )): #img.show() img.save("capturedd.png" % self._count) self._count += 1 elif key == keyboard.Key.alt_l or key == keyboard.Key.alt_r: self._alt_pressed = False elif key == keyboard.Key.esc: # Stop listener return False if __name__ == '__main__': kc = KC() with keyboard.Listener( on_press=kc.on_press, on_release=kc.on_release) as listener: listener.join() Using PyAV, you can directly encode these images to movie like this: #! /bin/env python # # NOTE: # Please stop running other capturing applications like 'DropBox' before # running this demonstration.
🌐
Note.nkmk.me
note.nkmk.me › home › python › pillow
Get the image from the clipboard with Python, Pillow | note.nkmk.me
April 22, 2022 - from PIL import ImageGrab, Image img = ImageGrab.grabclipboard() print(img) # <PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=200x71 at 0x105E68700> print(isinstance(img, Image.Image)) # True print(img.size) # (200, 71) print(img.mode) # RGB img.save('data/temp/clipboard_image.jpg')
🌐
Stack Overflow
stackoverflow.com › questions › 76242541 › how-can-i-see-what-did-pil-imagegrab-grab-captured-from-a-screen
python - How can I see what did PIL.ImageGrab.grab() captured from a screen? - Stack Overflow
Use screen.show() to see it on screen, or screen.save('grab.png') to save a file on disk. ... Thanks for hints Mark and Ken. Both works really nice. I appreciate it. ... from PIL import ImageGrab # Grab current screen. screen = ImageGrab.grab() ...
🌐
ProgramCreek
programcreek.com › python › example › 89032 › PIL.ImageGrab.grab
Python Examples of PIL.ImageGrab.grab
:param str save_to: Save screenshot to this PNG file path when expected count found or timeout. :param int timeout: Give up after these many seconds. :param iter subimg_candidates: Subimage paths to look for. List of strings. :param int expected_count: Keep trying until any of subimg_candidates ...
🌐
GitHub
github.com › python-pillow › Pillow › issues › 6126
ImageGrab.grab colors switched · Issue #6126 · python-pillow/Pillow
March 12, 2022 - python-pillow / Pillow Public · There was an error while loading. Please reload this page. Notifications · You must be signed in to change notification settings · Fork 2.4k · Star 13.4k · New issueCopy link · New issueCopy link · Closed · Closed · ImageGrab.grab colors switched#6126 · Copy link · BigDvsRL · opened · on Mar 12, 2022 · Issue body actions · screenshot2 = ImageGrab.grab(all_screens=True) That the ImageGrab saves the Image with the right colors^^ The colors are switched up.
Author   BigDvsRL
Find elsewhere
🌐
HolyPython
holypython.com › home › how to get a screenshot with python
How to get a Screenshot with Python | HolyPython.com
March 28, 2021 - PIL · HolyPython.com · All it takes is a 2 line implementation in Python: im=ImageGrab.grab() im.save("Screenshot.jpg") You might want to save this little code as “my_program.py” and schedule it with Windows so it takes screenshots of the computer at predefined intervals such as every hour or minute.
🌐
GitHub
github.com › python-pillow › Pillow › blob › main › src › PIL › ImageGrab.py
Pillow/src/PIL/ImageGrab.py at main · python-pillow/Pillow
msg = "wl-paste or xclip is required for ImageGrab.grabclipboard() on Linux" raise NotImplementedError(msg) · p = subprocess.run(args, capture_output=True) if p.returncode != 0: err = p.stderr · for silent_error in [ # wl-paste, when the clipboard is empty ·
Author   python-pillow
🌐
GitHub
github.com › python-pillow › Pillow › issues › 648
ImageGrab.grab().save(file) throws IOError: screen grab failed · Issue #648 · python-pillow/Pillow
May 8, 2014 - .... File "C:\Python27\Lib\sit... 56, in self.saveImage = lambda file: ImageGrab.grab().save(file) File "C:\Python27\Lib\site-packages\PIL\ImageGrab.py", ......
Author   kmelnikov
Top answer
1 of 2
6

There are many alternatives to PIL.ImageGrab.

If you want cross-platform, nearly every major windowing library has screen grab capabilities. Here's an example using PyQt4:

import sys
from PyQt4.QtGui import QPixmap, QApplication
app = QApplication(sys.argv)
QPixmap.grabWindow(QApplication.desktop().winId()).save('screenshot.jpg', 'jpg')

If you want something different from the default settings for what Qt considers "the desktop", you'll need to dig into the PyQt or Qt documentation.

The downside is that these cross-platform windowing libraries are usually pretty heavy duty in terms of installation, distribution, and even sometimes how you structure your program.

The alternative is to use Windows-specific code. While it's possible to ctypes your way directly to the Windows APIs, a much simpler solution is PyWin32.

import win32gui, win32ui, win32con, win32api
hwin = win32gui.GetDesktopWindow()
width = win32api.GetSystemMetrics(win32con.SM_CXVIRTUALSCREEN)
height = win32api.GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN)
left = win32api.GetSystemMetrics(win32con.SM_XVIRTUALSCREEN)
top = win32api.GetSystemMetrics(win32con.SM_YVIRTUALSCREEN)
hwindc = win32gui.GetWindowDC(hwin)
srcdc = win32ui.CreateDCFromHandle(hwindc)
memdc = srcdc.CreateCompatibleDC()
bmp = win32ui.CreateBitmap()
bmp.CreateCompatibleBitmap(srcdc, width, height)
memdc.SelectObject(bmp)
memdc.BitBlt((0, 0), (width, height), srcdc, (left, top), win32con.SRCCOPY)
bmp.SaveBitmapFile(memdc, 'screenshot.bmp')

As usual with Win32, you have to specify exactly what you mean by "the desktop"; this version specifies the "virtual screen" for the current session, which is the combination of all of the monitors if you're running locally at the console, or the remote view if you're running over Terminal Services. If you want something different, you'll have to read the relevant Win32 documentation at MSDN. But for the most part, translating from that documentation to PyWin32 is trivial.

(By the way, even though I say "Win32", the same all works for Win64.)

2 of 2
6

A modern cross-platform solution is to use Python MSS.

from mss import mss
from PIL import Image

def capture_screenshot():
    # Capture entire screen
    with mss() as sct:
        monitor = sct.monitors[1]
        sct_img = sct.grab(monitor)
        # Convert to PIL/Pillow Image
        return Image.frombytes('RGB', sct_img.size, sct_img.bgra, 'raw', 'BGRX')

img = capture_screenshot()
img.show()

On my slow laptop this function can return screenshots at up to 27 fps.

🌐
TutorialsPoint
tutorialspoint.com › python_pillow › python_pillow_imagegrab_grabclipboard_function.htm
Python Pillow - ImageGrab.grabclipboard()Function
from PIL import ImageGrab # Take a snapshot of the clipboard image clipboard_image = ImageGrab.grabclipboard() # Check for the clipboard object is an image or not if isinstance(clipboard_image, Image.Image): # Display or save the clipboard image clipboard_image.show() else: print("The clipboard does not contain image data.")
🌐
Stack Overflow
stackoverflow.com › questions › tagged › imagegrab
Newest 'imagegrab' Questions - Stack Overflow
However the saved image is always off by a bunch of pixels. I tried many exemples as well ... ... Recently I tried to use ImageGrab and replicate the screen.But when I writed following code and runed it after drawing Image was rotated diagonally. Does anyone know why this happens?Is problem with ... ... I was using ImageGrab from PIL...
🌐
Pillow
hugovk-pillow.readthedocs.io › en › stable › reference › ImageGrab.html
ImageGrab Module - Pillow (PIL Fork) 10.1.0 documentation
The ImageGrab module can be used to copy the contents of the screen or the clipboard to a PIL image memory.
🌐
Pillow Documentation
pillow.readthedocs.io › en › stable › reference › Image.html
Image module - Pillow (PIL Fork) 12.2.0 documentation
This method returns raw image data derived from Pillow’s internal storage. For compressed image data (e.g. PNG, JPEG) use save(), with a BytesIO parameter for in-memory data.
🌐
Nitratine
nitratine.net › blog › post › how-to-take-a-screenshot-in-python-using-pil
How To Take A Screenshot In Python Using PIL - Nitratine
August 24, 2020 - from PIL import ImageGrab screenshot = ImageGrab.grab(all_screens=True) # Take a screenshot that includes all screens
🌐
DevDungeon
devdungeon.com › content › grab-image-clipboard-python-pillow
Grab Image from Clipboard in Python with Pillow | DevDungeon
October 28, 2018 - You can get the bytes by simply using the same save() method used to write files. Instead of passing it a filename though, pass it an in-memory binary stream, BytesIO object. For more information on working with bytes and binary data, check ...