PIL ImageGrab Screenshot Guide | Generated by AI

Home 2025.10

Prerequisites

To use ImageGrab from the PIL (Pillow) library, ensure you have Pillow installed. On Windows, install it via pip:

pip install Pillow

No additional setup is typically needed for Windows, as ImageGrab uses native Windows APIs.

Basic Usage

ImageGrab.grab() captures the entire screen (all monitors) as a PIL Image object. Here’s a simple example to take a screenshot and save it as a PNG file:

from PIL import ImageGrab

# Capture the entire screen
screenshot = ImageGrab.grab()

# Save the image to a file
screenshot.save("screenshot.png")

This will save a file named screenshot.png in your current working directory.

Additional Options

Notes


Back

x-ai/grok-code-fast-1

Donate