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

For a straightforward desktop screenshot in Python, use PyAutoGUI: call pyautogui.screenshot(), then save the returned Pillow image. To capture only part of the screen, pass a region. Pillow’s ImageGrab and Python MSS are useful alternatives when you need different bounding-box, monitor, or pixel-data options. The right choice depends on your operating system and display session, so check the image dimensions and test the capture where the script will actually run.

Take and save a full-screen screenshot with PyAutoGUI

PyAutoGUI is a convenient starting point if your script may also control the mouse or keyboard. Its screenshot function returns a Pillow image, so you can inspect or modify the image before writing it to disk.

import pyautogui

image = pyautogui.screenshot()
image.save("screenshot.png")

Run the script in a graphical desktop session. After it completes, screenshot.png is written to the script’s current working directory. To choose another location, provide a path such as "captures/screenshot.png"; the parent directory must already exist or be created by your script.

PyAutoGUI also accepts a filename directly and returns the image:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Dell Optiplex 3060 Desktop Computer | Intel i5-8500 (3.2) | 32GB DDR4 RAM | 1TB SSD Solid State | Built in WiFi | Bluetooth | Windows 11 Professional | Home or Office PC (Renewed)
  • [INTEL POWERED CONTENT] - Built with a 8th Generation Hexa-Core Intel i5 and 32GB of DDR4 RAM; Modern, Windows 11 ready, with 4K support, Executive multitasking, media streaming and smooth, multi-tab web browsing; Perfect as an all-purpose multimedia computer; built for content creators; Plenty of RAM and Mass storage for photo and video editing powered by Intel HD 630
  • [LATEST WIRELESS TECH] - This Dell Desktop Computer easily connects to the internet through the Built In WiFi / Bluetooth
  • [SOLID STATE STORAGE] - This Dell Computer setup comes with an ultra-fast 1TB Solid State Drive (SSD); Setup as the primary boot device; Boot and load programs with lightning speed ; Additional expansion available
  • [BUY & OWN WITH CONFIDENCE] - From the world's largest Microsoft Authorized Refurbisher; Quality Guarantee and Free Tech Support; Award-winning Customer Service; | Support Sustainable Business
  • [MODERN HI-SPEED PORTS] - USB 3.0 (x4) | USB 2.0 (x4) | DisplayPort (x1) | HDMI Port (x1) | Audio Combo Jack (x1) | Audio Out (x1) | RJ-45 Ethernet (x1) | Internal SATA (x3)
import pyautogui

image = pyautogui.screenshot("screenshot.png")

The explicit save() version makes the capture and file-writing steps easier to separate. Use it if you want to crop, inspect, or otherwise work with the image before saving.

Install the package in the Python environment you will run

PyAutoGUI requires Pillow for screenshot capture. Install packages into the same virtual environment or Python interpreter used by your script, and follow the current platform-specific installation guidance for your PyAutoGUI version. Linux setups may need additional capture dependencies; the exact requirements depend on the distribution and desktop environment. A package installation by itself does not guarantee that a headless or remote session can capture a visible desktop.

Capture only part of the screen

With PyAutoGUI, pass region=(left, top, width, height). The first two values locate the top-left corner; the last two specify the captured width and height in pixels.

import pyautogui

image = pyautogui.screenshot(region=(100, 100, 640, 480))
image.save("region.png")

This asks for a 640-by-480-pixel area beginning at screen coordinate (100, 100). Coordinates are relative to the screen coordinate system reported to the capture library. On multi-monitor and high-density displays, do not assume that the coordinates map one-to-one to the pixels in the saved image; confirm the output dimensions and adjust against the target machine.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Dell Optiplex 7050 SFF Desktop PC Intel i7-7700 4-Cores 3.60GHz 32GB DDR4 1TB SSD WiFi BT HDMI Duel Monitor Support Windows 11 Pro Excellent Condition(Renewed)
  • Model: Dell OptiPlex 7050 Small Form Factor (SFF)
  • Processor: Intel Core i7-7700 3.60 GHz
  • Memory: 32GB DDR4 Ram
  • Storage: 1TB Solid State Drive (SSD) Fast Boot + Storage
  • Operating System: Windows 11 Pro (64-bit)

A region must describe an area within the available desktop. If the resulting capture is clipped or not the area you expected, check the display layout, monitor arrangement, and coordinate scale rather than assuming the tuple uses right and bottom endpoints.

Choose between PyAutoGUI, Pillow ImageGrab, and MSS

All three approaches can capture desktop content, but their interfaces and platform behavior differ. PyAutoGUI is a natural fit alongside GUI automation; Pillow’s ImageGrab is direct if the application already uses Pillow; MSS exposes monitor or region capture and screenshot data that can be converted to a Pillow image.

Library Basic result Area selection Monitor or window options Platform notes
PyAutoGUI Pillow image region=(left, top, width, height) Its documented screenshot interface captures the screen or a region; use its current documentation for version-specific behavior. Requires Pillow. The documentation identifies platform-specific capture requirements, including scrot for Linux.
Pillow ImageGrab Pillow image bbox=(left, top, right, bottom) Documentation covers Windows multi-screen and window options, and macOS window capture. On Linux, the documented fallback tools include gnome-screenshot, grim, or spectacle in some cases where the default X11 display does not return a snapshot.
MSS Screenshot data; convert with to_pil() for a Pillow image Choose a monitor or region for grab(). Its monitor list can be used to select a monitor; consult the installed version’s examples for region details. Capture behavior depends on the platform and display session. Check the current MSS documentation for setup details.

Use Pillow ImageGrab when a bounding box suits your code

ImageGrab.grab() captures the full screen by default. Its bbox takes the coordinates of the rectangle’s left, upper, right, and lower edges, rather than a starting point plus width and height.

from PIL import ImageGrab

image = ImageGrab.grab(bbox=(100, 100, 740, 580))
image.save("region.png")

Here the right endpoint is 740 and the lower endpoint is 580, giving a 640-by-480 rectangle from (100, 100). Mixing this convention up with PyAutoGUI’s width-and-height convention is a common source of incorrectly sized captures.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
HP All-in-OneDesktop Computer, 16GB DDR5 RAM, Intel Quad-Cores, 128GB SSD, WiFi6, Keyboard & Mouse, Windows 11
  • IMMERSIVE 24 INCH DISPLAY: Experience stunning clarity on a Full HD IPS screen with ultra-thin bezels, offering a 90% screen-to-body ratio that makes everything from spreadsheets to streaming come alive with vibrant colors and crisp details.
  • POWERFUL INTEL PROCESSING: Tackle demanding tasks with ease thanks to the Intel processor and 16GB of high-speed memory, delivering smooth performance whether you're multitasking between applications or running productivity software.
  • GENEROUS STORAGE: Store all your important files, photos, and programs with blazing-fast solid state drive technology that ensures quick boot times, rapid file access, and plenty of space for your digital life.
  • ENHANCED PRIVACY AND COLLABORATION: Work confidently with the pop-up privacy camera that tucks away when not in use, plus dual microphones with noise reduction for crystal-clear video calls that keep you connected professionally.
  • ECO-CONSCIOUS DESIGN: Feel good about your purchase with an EPEAT Gold registered and ENERGY STAR certified computer that combines premium performance with responsible environmental manufacturing practices.

Use MSS when you need to select a monitor

MSS can capture a selected monitor through its monitor collection and grab(). The following example uses the first listed monitor entry for capture and converts the result to a Pillow image for saving:

from mss import MSS

with MSS() as sct:
    image_data = sct.grab(sct.monitors[1])
    image = image_data.to_pil()
    image.save("monitor.png")

Check the current examples for the MSS version installed, especially if you need a particular monitor or a custom rectangle. Monitor numbering and the coordinates available to a capture library should be verified on the machine rather than assumed from another setup.

Account for macOS Retina scaling and image modes

Pillow documents that ImageGrab captures macOS Retina screens at 2× size by default. That means the returned image may have twice the expected pixel dimensions for a logical screen size. ImageGrab provides scale_down=True for 1× output:

from PIL import ImageGrab

image = ImageGrab.grab(scale_down=True)
image.save("screenshot.png")

When a script maps mouse or desktop coordinates onto image pixels, inspect image.size first and account for scaling. Pillow also documents different image modes by platform: macOS returns RGBA, while other platforms return RGB. Code that assumes three channels should handle or convert an RGBA image explicitly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Dell Optiplex 3050 SFF Desktop Computer PC, Intel Quad Core i5-6500 up to 3.6GHz, 16GB DDR4, 256GB SSD, WiFi, 4K Support, DP, HDMI, Windows 11 Pro 64 Bit (Renewed)
  • This Certified Refurbished product is tested and certified to look and work like new. The refurbishing process includes functionality testing, basic cleaning, inspection, and repackaging. The product ships with all relevant accessories, a minimum 90-day warranty, and may arrive in a generic box. Only select sellers who maintain a high-performance bar may offer Certified Refurbished products on Amazon.com.
  • Dell Optiplex 3050 SFF Desktop computer PC, Intel Quad Core i5-6500 up to 3.6GHz, 16GB DDR4, 256GB SSD
  • Includes: USB Keyboard & Mouse, USB WiFi adapter, Microsoft office 30 days free trail.
  • Port: Front: USB 3.0(2), USB 2.0(2); Rear: DP, HDMI, USB 3.0(2), USB 2.0(2), RJ-45.
  • Support 4K (3840x2160) Dual display, makes it easy to connect two monitors at the same time, and you can expand working Windows, mirror content, or expand a single window across multiple monitors.

Save in the format your next step needs

The examples save PNG files, which Pillow can write through the image’s save() method. If another program expects a different format, choose the extension and format deliberately and check the resulting file. Image mode can matter when converting or opening captures downstream; for example, a consumer that expects RGB may need an RGBA image converted first.

from PIL import ImageGrab

image = ImageGrab.grab()
if image.mode == "RGBA":
    image = image.convert("RGB")
image.save("screenshot.png")

Do not infer the capture’s pixel dimensions from the monitor’s advertised resolution alone. Retina scaling, a selected monitor, a region, or desktop coordinate behavior can all affect the image you receive. Log or inspect the dimensions during setup so downstream crops, OCR, or image comparisons use the actual image size.

Performance, reliability, and cost considerations

There is no current controlled comparison here that establishes one of these libraries as universally fastest. Capture time depends on the operating system, display session, resolution, backend, and workload. If latency matters, benchmark the exact library and capture pattern on the machine and session where the script will run. Avoid treating an older documentation estimate for a 1920 × 1080 PyAutoGUI screenshot as a current guarantee.

For reliability, run the script under the same account and graphical session as the intended use, and verify both that an image file was created and that it contains the expected screen. Headless and remote-desktop behavior, as well as current OS privacy permission prompts, can vary; if a capture is blank or denied, consult the current operating-system and library guidance for that environment.

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.
Best Value
Dell Windows 11 Desktop Computer OptiPlex 5060 | Intel Core i5-8500 Six Core (4.3GHz Turbo) | 16GB DDR4 RAM | 500GB SSD Solid State + 1TB HDD | WiFi + Bluetooth | Home or Office PC (Renewed)
  • Connectivity: Includes WiFi, Bluetooth, and LAN for wireless and wired connections
  • Memory: Features 16GB DDR4 RAM for smooth multitasking and performance
  • Storage: Combines 500GB SSD and 1TB HDD for ample storage space
  • Graphics: Integrated Intel UHD Graphics 630 for crisp visuals and video playback
  • Design: Sleek desktop tower with black color and slim profile for modern look

These Python libraries are software approaches and do not require purchasing a physical capture device for an ordinary desktop screenshot. Their practical cost is the setup and maintenance of compatible packages and platform dependencies.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common capture problems

  • ImportError for PyAutoGUI or Pillow: The package may have been installed into a different Python environment. Activate the environment used to run the script and install according to the current package instructions there. PyAutoGUI’s screenshot function depends on Pillow.
  • Linux capture fails or returns no image: Capture backends and desktop sessions differ. PyAutoGUI documents a Linux dependency on scrot; Pillow ImageGrab documents fallback options including gnome-screenshot, grim, or spectacle for certain X11 cases. Use the instructions for the library and distribution you selected instead of applying one library’s dependency list to another.
  • The image is blank or capture is denied: Confirm that the process can access an active graphical display and check current privacy or screen-recording permission settings for your operating system. Headless and remote sessions may behave differently; the available documentation does not establish one fix that applies to every setup.
  • The region is shifted or has the wrong size: Verify whether the API expects width and height or rectangle endpoints. PyAutoGUI takes (left, top, width, height); Pillow ImageGrab takes (left, top, right, bottom). Then compare the requested coordinates with the actual image dimensions and monitor layout.
  • The macOS image has unexpected dimensions or channels: Pillow ImageGrab documents 2× Retina capture by default and an optional scale_down=True. It also returns RGBA on macOS; inspect image.size and image.mode before handing the image to code that assumes another size or RGB.
  • The output file is missing: Check the script’s current working directory and ensure the target directory exists. Save to an explicit path if the script is launched from a scheduler, IDE, or another location that changes its working directory.

Or skip the browser setup

A local Python desktop capture and a website screenshot API solve different problems: ScreenshotNeo captures a web page from its URL, not your computer’s desktop. If the goal is to capture a site, one GET request saves the returned image:

import requests

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

See the ScreenshotNeo API documentation for request options. Cookie banners and consent overlays, newsletter popups, and chat widgets are removed before capture; those cleanup steps can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server offers screenshot tools for AI agents, including 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. Sign up for 1,000 free screenshots a month, with no card required.

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

Frequently Asked Questions

Can PyAutoGUI capture a screenshot while my Python script is running in the background?

A screenshot needs access to a graphical desktop display. Whether a background, scheduled, remote, or headless process can see that display depends on the operating system and session configuration; verify it in the same launch context as the deployed script.

How can I tell whether the screenshot contains the intended monitor?

Inspect the saved image’s dimensions and content on the target machine. Monitor selection and coordinate behavior depend on the capture library and display setup, so validate them rather than inferring the result from the monitor’s name alone.

Quick Recap

Bestseller No. 2
Dell Optiplex 7050 SFF Desktop PC Intel i7-7700 4-Cores 3.60GHz 32GB DDR4 1TB SSD WiFi BT HDMI Duel Monitor Support Windows 11 Pro Excellent Condition(Renewed)
Dell Optiplex 7050 SFF Desktop PC Intel i7-7700 4-Cores 3.60GHz 32GB DDR4 1TB SSD WiFi BT HDMI Duel Monitor Support Windows 11 Pro Excellent Condition(Renewed)
Model: Dell OptiPlex 7050 Small Form Factor (SFF); Processor: Intel Core i7-7700 3.60 GHz; Memory: 32GB DDR4 Ram
$402.99
Bestseller No. 4
Dell Optiplex 3050 SFF Desktop Computer PC, Intel Quad Core i5-6500 up to 3.6GHz, 16GB DDR4, 256GB SSD, WiFi, 4K Support, DP, HDMI, Windows 11 Pro 64 Bit (Renewed)
Dell Optiplex 3050 SFF Desktop Computer PC, Intel Quad Core i5-6500 up to 3.6GHz, 16GB DDR4, 256GB SSD, WiFi, 4K Support, DP, HDMI, Windows 11 Pro 64 Bit (Renewed)
Includes: USB Keyboard & Mouse, USB WiFi adapter, Microsoft office 30 days free trail.; Port: Front: USB 3.0(2), USB 2.0(2); Rear: DP, HDMI, USB 3.0(2), USB 2.0(2), RJ-45.
$169.98
Bestseller No. 5
Dell Windows 11 Desktop Computer OptiPlex 5060 | Intel Core i5-8500 Six Core (4.3GHz Turbo) | 16GB DDR4 RAM | 500GB SSD Solid State + 1TB HDD | WiFi + Bluetooth | Home or Office PC (Renewed)
Dell Windows 11 Desktop Computer OptiPlex 5060 | Intel Core i5-8500 Six Core (4.3GHz Turbo) | 16GB DDR4 RAM | 500GB SSD Solid State + 1TB HDD | WiFi + Bluetooth | Home or Office PC (Renewed)
Connectivity: Includes WiFi, Bluetooth, and LAN for wireless and wired connections; Memory: Features 16GB DDR4 RAM for smooth multitasking and performance
$255.00

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.