Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The shortest working solution is PyAutoGUI: install it with python -m pip install pyautogui, then run pyautogui.screenshot('screenshot.png'). The call saves a PNG and returns a Pillow image object. For a desktop screenshot, however, the best library depends on whether you need a simple script, a cropped rectangle, multiple monitors, or repeated high-speed captures.

Install a Python screenshot library

Use the environment that will actually run the script:

python -m pip install pyautogui pillow mss

You only need the package for the method you choose. PyAutoGUI requires Pillow for screenshot support. On Linux, PyAutoGUI documents scrot as an additional requirement; install it with your distribution’s package manager if captures fail. Pillow ImageGrab can depend on XCB or a desktop screenshot utility such as gnome-screenshot, grim, or spectacle, depending on the Linux session.

A screenshot must run inside a desktop session that exposes a display. A headless server, container without display access, locked-down remote session, or denied operating-system permission may not provide pixels for any library to capture.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents

Method 1: PyAutoGUI for the shortest script

Capture the entire screen

import pyautogui

image = pyautogui.screenshot('screenshot.png')
print(image.size)

The filename ending in .png makes the output a PNG. The returned value is a Pillow image, so you can inspect it or process it further before saving another copy.

Capture only a rectangle

import pyautogui

image = pyautogui.screenshot(
    'region.png',
    region=(0, 0, 800, 600),
)

PyAutoGUI’s region tuple is (left, top, width, height). Coordinates begin at the desktop’s screen origin. The example captures an 800-by-600 rectangle at the upper-left corner.

When PyAutoGUI is the right choice

  • Use it when you want a compact script that may later move the mouse, click, type, or press keys.
  • It is convenient for one-off full-screen or rectangular captures.
  • Its documentation gives an approximate 100-millisecond capture time for a 1,920 × 1,080 screen. That is an environment-specific example, not a universal benchmark; display hardware, operating system, encoding, and desktop load change the result.

Method 2: Pillow ImageGrab for direct capture

Save a full screen

from PIL import ImageGrab

full = ImageGrab.grab()
full.save('full-screen.png')

Save a cropped region

from PIL import ImageGrab

part = ImageGrab.grab(bbox=(0, 0, 800, 600))
part.save('region.png')

ImageGrab uses a different rectangle convention from PyAutoGUI: bbox=(left, upper, right, lower). The last two values are coordinates of the lower-right boundary, not width and height. Thus (0, 0, 800, 600) produces an 800-by-600 region.

When ImageGrab is the right choice

  • Choose it when Pillow is already part of your application.
  • It provides a small API for full-screen and bounding-box captures without desktop automation features.
  • On Linux, verify the display backend and any utility required by your desktop environment before debugging Python code.

Method 3: MSS for monitors, regions, and repeated captures

Capture a monitor and encode PNG

import mss
import mss.tools

with mss.MSS() as sct:
    monitor = sct.monitors[1]
    shot = sct.grab(monitor)
    mss.tools.to_png(shot.rgb, shot.size, output='monitor.png')

MSS exposes monitor definitions through sct.monitors. Select the entry you need rather than assuming every computer has the same monitor count or ordering.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Capture an explicit rectangle

import mss
import mss.tools
from mss.models import Region

with mss.MSS() as sct:
    region = Region(left=100, top=100, width=800, height=600)
    shot = sct.grab(region)
    mss.tools.to_png(shot.rgb, shot.size, output='region.png')

Convert to Pillow for further processing

import mss

with mss.MSS() as sct:
    shot = sct.grab(sct.monitors[1])
    image = shot.to_pil('RGB')
    image.save('monitor.png')

Use MSS when you need explicit monitor selection, repeated captures, direct pixel data, or a documented PNG helper. Its region object uses left, top, width, and height, matching the way most capture loops describe a rectangle.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

Which Python method should you choose?

Need Best starting point Reason Coordinates
Smallest automation script PyAutoGUI One call saves the image and can later be combined with mouse and keyboard automation. (left, top, width, height)
Pillow-based image workflow ImageGrab Returns a Pillow image directly for cropping, drawing, or other processing. (left, upper, right, lower)
Multiple monitors or capture loops MSS Provides monitor definitions, explicit regions, raw pixels, and PNG conversion. Region fields: left, top, width, height

All three methods produce image data that can be saved with a filename ending in .png. PNG is lossless; the extension and encoder determine the output format, not the act of capturing the screen itself.

Build a reusable PNG capture script

This PyAutoGUI example accepts an optional rectangle, creates parent directories, and reports the result:

from pathlib import Path
import argparse
import pyautogui

parser = argparse.ArgumentParser()
parser.add_argument('output', nargs='?', default='screenshots/shot.png')
parser.add_argument('--region', nargs=4, type=int, metavar=('LEFT', 'TOP', 'WIDTH', 'HEIGHT'))
args = parser.parse_args()

output = Path(args.output)
output.parent.mkdir(parents=True, exist_ok=True)
region = tuple(args.region) if args.region else None
image = pyautogui.screenshot(str(output), region=region)
print(f'Saved {output} ({image.width}x{image.height})')

Examples:

python capture.py
python capture.py build.png --region 100 80 1200 700

Use absolute paths when a scheduler or service might have a different working directory. Check the reported dimensions before sending the file to another system.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Platform and display details

Windows

Run the script in the logged-in desktop session whose pixels you intend to capture. Window minimization, display scaling, and multiple-monitor arrangements can change coordinates and image dimensions.

macOS

If the capture is blank or incomplete, check the operating system’s Screen Recording or related privacy permission for the terminal, IDE, or Python executable that launches the script. Grant access to the actual application, then restart it if macOS requires a permission refresh.

Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

Linux

Confirm that the process has access to the active graphical session. PyAutoGUI documents scrot; ImageGrab may use XCB or utilities such as gnome-screenshot, grim, or spectacle. Wayland and X11 sessions can expose different capture capabilities, so follow the prerequisite documented for your chosen library rather than assuming one package works everywhere.

Headless execution

These libraries capture a display, not an abstract web page. A headless machine without a display server cannot be made reliable by changing only the Python call. Use a real desktop session or a separately configured virtual display, and treat that setup as an infrastructure requirement.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

PNG quality, size, and performance

Lossless output

PNG preserves screen pixels and is suitable for text, interfaces, diagrams, and later image processing. It can be larger than JPEG for photographic content. If storage or transfer size matters, capture PNG first when exact pixels are important, then deliberately convert a copy to another format.

Repeated captures

Do not create and destroy expensive resources inside a tight loop unnecessarily. MSS is designed around a persistent MSS() context and gives direct pixel access, making it a practical starting point for repeated captures. Limit the captured region, frame rate, and output resolution to what the application actually needs.

Timing and synchronization

A screenshot call can return before an animation, window redraw, or application update is visually complete. Add your own application-level wait, poll for the state you need, or capture after an explicit user-interface event. The approximately 100 ms PyAutoGUI figure applies only to the documented 1,920 × 1,080 example and should not be used as a cross-library performance promise.

Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting common failures

ModuleNotFoundError

Install the package into the same interpreter that runs the script: python -m pip install pyautogui, python -m pip install pillow, or python -m pip install mss. In an IDE, verify its selected virtual environment.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Linux reports a missing utility or cannot connect to the display

Install the utility named by your library and run from a session with display access. Check the session’s display variables and desktop permissions. A remote shell without the graphical session will not automatically inherit capture access.

The file exists but is black, empty, or partially drawn

Check macOS Screen Recording permission, confirm that the target window is visible, and wait for the application to finish rendering. On Linux, verify whether your Wayland or X11 session supports the selected backend. For a web page, a browser window must be open and displaying the page; these libraries do not fetch a URL by themselves.

The crop is the wrong size

Review the coordinate convention. PyAutoGUI and MSS use width and height; Pillow uses right and lower coordinates. Also account for display scaling and the origin of secondary monitors, which may use negative desktop coordinates.

MSS captures the wrong monitor

Inspect sct.monitors and choose the entry that describes the intended monitor. Do not hard-code an index copied from another computer with a different monitor layout.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

Permission errors when saving

Save to a directory where the process has write permission, create the directory first, and use a full path when running from a service or scheduler. The capture may succeed even when the subsequent file write fails.

Or skip the browser setup

If what you really need is a screenshot of a website rather than the physical desktop, ScreenshotNeo returns a PNG, JPEG, WebP, or PDF from one request. Its clean-shot steps accept cookie or consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be disabled.

Use the Python API call below; the API documentation is at https://screenshotneo.com/docs/:

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)

Despite the example filename, the response format is controlled by the API options; request PNG when you need PNG output. The same endpoint can be called with cURL:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Or with Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
  • Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing; response headers identify the page verdict and whether the request was billed.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
  • The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 screenshots, and every feature is available on every plan.

Create a free ScreenshotNeo account to try website captures without configuring a browser.

Frequently Asked Questions

Can Python capture a screenshot without opening a browser?

Yes. PyAutoGUI, Pillow ImageGrab, and MSS capture the desktop display directly. They still require an accessible graphical session.

Why is my PNG larger than expected?

PNG is lossless and records every pixel. Large screens, high-retina scaling, and detailed photographic content naturally produce larger files; crop the region or resize a copy when exact full resolution is unnecessary.

Which coordinate format should I use for a crop?

PyAutoGUI uses left, top, width, height. Pillow ImageGrab uses left, upper, right, lower. MSS uses named left, top, width, and height fields.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.