🌐
Pillow Documentation
pillow.readthedocs.io › en › stable › reference › ImageGrab.html
ImageGrab module - Pillow (PIL Fork) 12.2.0 documentation
PIL.ImageGrab.grab(bbox=None, include_layered_windows=False, all_screens=False, xdisplay=None, window=None)[source]¶
🌐
GeeksforGeeks
geeksforgeeks.org › python-pil-imagegrab-grab-method
Python PIL | ImageGrab.grab() method - GeeksforGeeks
May 3, 2022 - # Importing Image and ImageGrab ... be used for different screen sizes. ... PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities....
Discussions

Question about PIL's ImageGrab.grab() function...
Since it only takes two opposite corners to define a rectangle, the first two are the coordinates of the upper left corner and the other two are the coordinates of the bottom right corner. More on reddit.com
🌐 r/learnpython
2
1
December 6, 2022
python - How can I see what did PIL.ImageGrab.grab() captured from a screen? - Stack Overflow
I'm using pyautogui to automate some browser process on Windows. To get data from screen I do screenshot grab with ImageGrab from Pillow. Then I do OCR with Tesseract module pytesseract. I know how... More on stackoverflow.com
🌐 stackoverflow.com
python - Is there any better way to capture the screen than PIL.ImageGrab.grab()? - Stack Overflow
I am making a screen capture program with python. My current problem is PIL.ImageGrab.grab() gives me the same output as 2 seconds later. For instance, for I think I am not being clear, in the foll... More on stackoverflow.com
🌐 stackoverflow.com
python - Is there a way to use ImageGrab on a specific window? (PIL) - Stack Overflow
This code is suppused to take a screenshot of a specific window using ImageGrab(PIL), however the screenshot is not acurrate and I have no Idea why. here is a screenshot the code took(both not the ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
TutorialsPoint
tutorialspoint.com › python_pillow › python_pillow_imagegrab_grab_function.htm
Python Pillow - ImageGrab.grab()Function
In this example, the ImageGrab.grab() function is used to capture a specific region of the screen. from PIL import ImageGrab # Specify bounding box bbox = (100, 100, 500, 500) # Capture a specific region (bbox) captured_image = ImageGrab.grab(bbox=bbox) # Display the captured image captured_image.show() print('Captured the snapshot successfully...')
🌐
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, )): dimg = ImageOps.expand( img, border=((self._vstream.width - img.width) // 2, (self._vstream.height - img.height) // 2)) vframe = av.VideoFrame.from_image(dimg) logging.debug(vframe) for i in range(self._repeat): for p in self._vstream.encode(vframe): logging.debug(p) self._container.mux(p) elif key == keyboard.Key.alt_l or key == keyboard.Key.alt_r: self._alt_pressed = False elif key == keyboard.Key.esc: try: # flush the rest in queue.
🌐
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
🌐
ProgramCreek
programcreek.com › python › example › 89032 › PIL.ImageGrab.grab
Python Examples of PIL.ImageGrab.grab
:param int expected_count: Keep trying until any of subimg_candidates is found this many times. :param iter gen: Generator yielding window position and size to crop screenshot to. """ from PIL import ImageGrab assert save_to.endswith('.png') stop_after = time.time() + timeout # Take screenshots until subimage is found.
🌐
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
from PIL import ImageGrab # Grab current screen. screen = ImageGrab.grab() # Save as temp file and open it using your assigned program. screen.show() # Save it in a modern format.
Find elsewhere
🌐
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') ... If any non-image, such as text, is copied on the clipboard, ImageGrab.grabclipboard() returns None. ... Draw circle, rectangle, line, etc. with Python, Pillow
🌐
Pillow Documentation
pillow.readthedocs.io › en › stable › _modules › PIL › ImageGrab.html
PIL.ImageGrab - Pillow (PIL Fork) 12.2.0 documentation
[docs] def grab( bbox: tuple[int, int, int, int] | None = None, include_layered_windows: bool = False, all_screens: bool = False, xdisplay: str | None = None, window: int | ImageWin.HWND | None = None, ) -> Image.Image: im: Image.Image if xdisplay is None: if sys.platform == "darwin": fh, filepath = tempfile.mkstemp(".png") os.close(fh) args = ["screencapture"] if window is not None: args += ["-l", str(window)] elif bbox: left, top, right, bottom = bbox args += ["-R", f"{left},{top},{right-left},{bottom-top}"] args += ["-x", filepath] retcode = subprocess.call(args) if retcode: raise subproces
🌐
Pillow
pillow.readthedocs.io › en › latest › _modules › PIL › ImageGrab.html
PIL.ImageGrab - Pillow (PIL Fork) 12.1.0.dev0 documentation
[docs] def grab( bbox: tuple[int, int, int, int] | None = None, include_layered_windows: bool = False, all_screens: bool = False, xdisplay: str | None = None, window: int | ImageWin.HWND | None = None, ) -> Image.Image: im: Image.Image if xdisplay is None: if sys.platform == "darwin": fh, filepath = tempfile.mkstemp(".png") os.close(fh) args = ["screencapture"] if window: args += ["-l", str(window)] elif bbox: left, top, right, bottom = bbox args += ["-R", f"{left},{top},{right-left},{bottom-top}"] subprocess.call(args + ["-x", filepath]) im = Image.open(filepath) im.load() os.unlink(filepath)
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.

🌐
GeeksforGeeks
geeksforgeeks.org › python › pyhton-pil-imagegrab-grabclipboard-method
Python PIL | ImageGrab.grabclipboard() method - GeeksforGeeks
July 29, 2019 - Syntax: PIL.ImageGrab.grabclipboard() Parameters: no arguments Returns: On Windows, an image, a list of filenames, or None if the clipboard does not contain image data or filenames.
🌐
Stack Overflow
stackoverflow.com › questions › 72746424 › is-there-a-way-to-use-imagegrab-on-a-specific-window-pil
python - Is there a way to use ImageGrab on a specific window? (PIL) - Stack Overflow
import pygetwindow as gw import PIL.ImageGrab from pynput.mouse import Button, Controller mouse = Controller() from pynput.keyboard import Key, Controller keyboard = Controller() chosenWindow = gw.getWindowsWithTitle('Discord')[0] print(chosenWindow.topleft) print(chosenWindow.bottomright) Im = PIL.ImageGrab.grab(bbox=(chosenWindow.topleft[0],chosenWindow.topleft[1],chosenWindow.bottomright[0],chosenWindow.bottomright[1])) Im.show()
🌐
Stack Overflow
stackoverflow.com › questions › 73258053 › how-to-use-image-from-pil-imagegrab-without-saving-it-to-a-file
python - How to use image from PIL ImageGrab without saving it to a file? - Stack Overflow
How can I correctly use the result of ImageGrab.grab without using .save and then cv2.imread? ... Your question confuses me, but I think you want to get a Numpy array, like you would from cv2.imread() so that you can use it with scikit-image. But you currently have a PIL Image instead.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-using-pil-imagegrab-and-pytesseract
Python | Using PIL ImageGrab and PyTesseract - GeeksforGeeks
July 12, 2025 - Code : Python code to use ImageGrab and PyTesseract ... # cv2.cvtColor takes a numpy ndarray as an argument import numpy as nm import pytesseract # importing OpenCV import cv2 from PIL import ImageGrab def imToString(): # Path of tesseract executable pytesseract.pytesseract.tesseract_cmd ='**Path to tesseract executable**' while(True): # ImageGrab-To capture the screen image in a loop.
🌐
Pillow Documentation
pillow.readthedocs.io › en › stable › reference › Image.html
Image module - Pillow (PIL Fork) 12.2.0 documentation
This is a lazy operation; this function identifies the file, but the file remains open and the actual image data is not read from the file until you try to process the data (or call the load() method). See new(). See File handling in Pillow.
🌐
GitHub
github.com › python-pillow › Pillow › issues › 6126
ImageGrab.grab colors switched · Issue #6126 · python-pillow/Pillow
March 12, 2022 - What did you do? screenshot2 = ImageGrab.grab(all_screens=True) What did you expect to happen? That the ImageGrab saves the Image with the right colors^^ What actually happened? The colors are swit...
Author   BigDvsRL