Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk5 min

How to Capture Screenshots in Python with MSS

Use Python MSS to capture the primary monitor, select a physical display or region, save a PNG, and convert screenshot data for image processing.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use MSS’s current MSS class to capture a monitor or screen region. For a PNG file, the shortest path is sct.shot(); for a crop or image processing, use sct.grab() and save or convert the returned screenshot object.

Install MSS and capture a monitor

Install the library in the Python environment where your script will run:

python -m pip install mss

The current documented entry point is MSS, used as a context manager. This example captures the primary monitor and writes a PNG:

from mss import MSS

with MSS() as sct:
    filename = sct.shot()
    print(f"Saved screenshot to {filename}")

shot() is a convenient file-output helper. To select the monitor explicitly, or to use the pixels in Python, call grab():

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
from mss import MSS

with MSS() as sct:
    screenshot = sct.grab(sct.primary_monitor)
    print(screenshot.size)

grab() returns an MSS ScreenShot object rather than a filename. For simple monitor output, MSS also documents save(); use grab() when you need control over the capture rectangle or the image data.

Choose a monitor correctly

MSS exposes monitor geometry through sct.monitors. Index 0 is the combined virtual screen spanning all monitors, not the first physical display. Individual monitor entries start at index 1.

Rank #2
Dell Latitude 3190 11.6" HD 2-in-1 Touchscreen Laptop Intel N5030 1.1Ghz 4GB Ram 128GB SSD Windows 11 Professional (Renewed)
  • 1.1 GHz (boost up to 2.4GHz) Intel Celeron N5030 Quad-Core
  • 4GB DDR4 System Memory; 128GB Solid State Drive
  • 11.6" HD (1366 x 768) Multi-Touch Display
  • Combo headphone/microphone jack - Noble Wedge Lock slot - HDMI; 2 USB 3.1 Gen 1
  • Windows 11 Pro
from mss import MSS

with MSS() as sct:
    for index, monitor in enumerate(sct.monitors):
        print(index, monitor)

    first_physical_monitor = sct.grab(sct.monitors[1])

Use sct.primary_monitor when you specifically want the primary display. Use an entry from sct.monitors when the user should choose a physical monitor or the entire virtual desktop. Because monitors may have negative or nonzero origins in a multi-display layout, rely on each monitor’s left, top, width, and height values instead of assuming every display begins at (0, 0).

Capture and save a screen region

A region is described with its screen-coordinate origin and dimensions. The example below grabs a 320-by-240 rectangle and writes its RGB data as a PNG:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Dell Latitude 5420 14" FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
  • 256 GB SSD of storage.
  • Multitasking is easy with 16GB of RAM
  • Equipped with a blazing fast Core i5 2.00 GHz processor.
import mss.tools
from mss import MSS
from mss.models import Region

region = Region(left=160, top=160, width=320, height=240)

with MSS() as sct:
    image = sct.grab(region)
    mss.tools.to_png(image.rgb, image.size, output="region.png")

The coordinates above are relative to the virtual screen coordinate system. To crop relative to another monitor, add the crop’s offset to that monitor’s own origin:

from mss import MSS
from mss.models import Region

with MSS() as sct:
    monitor = sct.monitors[1]
    region = Region(
        left=monitor.left + 100,
        top=monitor.top + 80,
        width=400,
        height=300,
    )
    image = sct.grab(region)

MSS also accepts a PIL-style bounding box in the form (left, top, right, bottom) for grab(). In that form, right and bottom are the far edges of the rectangle; with a Region, specify width and height instead.

Rank #4
15.6 Inch Laptop Computer, N4020, 4GB DDR4 RAM, 128GB eMMC,with Windows 11
  • EFFORTLESS EVERYDAY PERFORMANCE: Powered by Intel Celeron N4020 processor and Windows 11 Home system, delivering reliable, low-power efficiency for daily tasks like document editing, email, online classes, and web browsing
  • 15.6-INCH FULL HD DISPLAY: Enjoy immersive visuals on the 15.6" FHD (1920x1080) anti-glare screen with micro-edge bezels. Delivers clear details and comfortable viewing for long study sessions, working on spreadsheets, and video playback
  • RESPONSIVE MULTITASKING & STORAGE: Built with 4GB LPDDR4 RAM and 128GB eMMC storage for smooth daily essential use. Expand your storage by up to 1TB via the integrated TF card slot to easily store movies, photos, and working files
  • ADVANCED CONNECTIVITY: Outfitted with 2x Full-Featured Type-C ports for data transfer, fast charging, and dual-monitor output, alongside 2x USB 3.2 Gen1 ports and a 3.5mm audio jack for complete peripheral compatibility
  • LIGHTWEIGHT & SILENT OPERATION: Slim and portable for effortless travel or commuting. Features a 1MP HD webcam for remote meetings, 38Wh battery with 45W Type-C fast charging, and a fanless silent design for peaceful work environments.

Save bytes or prepare the screenshot for image processing

If you need a PNG byte string rather than a file, omit the output filename from to_png():

import mss.tools
from mss import MSS

with MSS() as sct:
    image = sct.grab(sct.primary_monitor)
    png_bytes = mss.tools.to_png(image.rgb, image.size)
    print(len(png_bytes))

For Pillow operations, convert the MSS screenshot object with to_pil():

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
15.6 Inch Win 11 Laptop Computer, N4020, 4GB DDR4 RAM, 128GB Storage
  • WINDOWS 11 | STABLE PERFORMANCE: Powered by Intel Celeron N4020 processor and Windows 11 system, this laptop delivers stable performance for everyday computing tasks. It supports web browsing, online learning, document editing, email communication, and basic office work with optimized power efficiency, providing a practical and reliable experience for essential daily use for daily use.
  • 15.6” FHD IPS DISPLAY: Features a 15.6-inch Full HD IPS display with narrow bezels, offering wider viewing angles and clearer image details compared to standard panels. The improved screen-to-body ratio enhances visual experience for study, reading, document work, and video playback, making it suitable for both productivity and entertainment use.
  • 4GB DDR4 + 128GB eMMC STORAGE: Equipped with 4GB DDR4 memory and 128GB eMMC storage for everyday basics such as browsing, documents, email, and online learning platforms. The built-in TF card slot supports storage expansion up to 1TB, giving you more flexibility for files, photos, videos, and daily documents. TF card not included.
  • CONNECTIVITY & PORTS: Includes 1× TF card slot, 2× USB 3.2 Gen1 ports, and 2× full-featured Type-C ports (USB 3.2 Gen1). The Type-C ports support data transfer, charging, and video output, enabling flexible connection with external devices such as monitors, storage, and peripherals for daily work and study use.
  • LIGHTWEIGHT DESIGN | ONLINE COMMUNICATION: Designed with a slim, portable profile, this laptop is easy to carry for school, commuting, and travel. A built-in 1MP front camera supports online classes, video meetings, remote communication, and everyday conferencing. The 3300mAh battery works with the low-power system design to support practical daily use, while thermal optimization helps maintain quieter operation during extended tasks.
from mss import MSS

with MSS() as sct:
    image = sct.grab(sct.primary_monitor)
    pil_image = image.to_pil()
    pil_image.save("screen.png")

For computer vision or pixel analysis, the screenshot object exposes pixel data and a buffer interface. Compatible libraries such as NumPy and OpenCV can work with screenshot buffers in ways that reduce copying; whether that is useful depends on the library and processing pipeline. If the sole goal is a PNG on disk, the direct file-saving helpers are simpler.

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

Choose MSS or Pillow based on the job

MSS is a natural fit when you need to enumerate monitors, select a monitor or coordinate-based region, or consume its screenshot object and buffer. Pillow’s ImageGrab.grab() returns a Pillow image and accepts a bbox, which may suit a workflow that already uses Pillow. The documented platform behavior differs: Pillow reports RGB output on most platforms and RGBA on macOS, supports Retina scaling options on macOS, and documents Linux screenshot-tool fallbacks when the default X11 display does not return an image. Neither interface is established as universally better; choose according to your display environment, multi-monitor needs, and desired image representation.

Display-server and environment considerations

Capturing a desktop requires an accessible display. On Linux, the MSS usage documentation describes xshmgetimage as the default backend, with a fallback to xgetimage when MIT-SHM is unavailable, such as on some remote SSH displays. It also describes xgetimage as a compatibility option and xlib as a legacy backend. Those backend details do not establish that every headless, remote, or Wayland environment will work without additional setup; verify the requirements for the actual display session and operating system.

Troubleshooting common capture problems

  • The capture is the wrong display: check the printed sct.monitors list. Entry 0 covers the virtual desktop; choose an entry from index 1 onward for an individual monitor, or use primary_monitor.
  • A crop is shifted or empty: inspect the selected monitor’s left and top values and include them when calculating a region on a monitor whose origin is not zero. Confirm that width and height stay within the intended screen area.
  • The script fails to access a display: confirm that the process runs in a session with an available desktop display. For Linux remote or headless setups, check the display server and backend requirements rather than assuming a desktop screenshot is available.
  • Older examples fail or produce deprecation warnings: prefer from mss import MSS and with MSS() as sct. The older mss.mss() spelling remains available for compatibility but is deprecated in the current usage guide.
  • You expected a Pillow image: grab() returns an MSS screenshot object. Call to_pil() to create a Pillow image, or use Pillow’s own ImageGrab.grab() if a Pillow-first interface is preferable.

Or skip the browser setup

MSS captures the computer’s existing display. If your goal is a website screenshot rather than a desktop screenshot, ScreenshotNeo provides a website screenshot API and MCP server. One GET request can return an image or PDF; cookie banners, newsletter popups, and chat widgets are removed before the shot, and bot checks, blank pages, failed loads, and cache hits are not billed. Its MCP server lets AI agents use screenshot tools, and the free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots.

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

For the full parameters and response details, see the ScreenshotNeo API documentation. Example using cURL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Sign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, no card required.

Quick Recap

Bestseller No. 1
HP 14' HD Laptop, Windows 11, Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD, Webcam, Dale Pink (Renewed)
HP 14" HD Laptop, Windows 11, Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD, Webcam, Dale Pink (Renewed)
14" diagonal, 1366x768 resolution, HD BrightView LED, Glossy NON-TOUCH Display
$249.99
Bestseller No. 2
Dell Latitude 3190 11.6' HD 2-in-1 Touchscreen Laptop Intel N5030 1.1Ghz 4GB Ram 128GB SSD Windows 11 Professional (Renewed)
Dell Latitude 3190 11.6" HD 2-in-1 Touchscreen Laptop Intel N5030 1.1Ghz 4GB Ram 128GB SSD Windows 11 Professional (Renewed)
1.1 GHz (boost up to 2.4GHz) Intel Celeron N5030 Quad-Core; 4GB DDR4 System Memory; 128GB Solid State Drive
$179.99
Bestseller No. 3
Dell Latitude 5420 14' FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
Dell Latitude 5420 14" FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
256 GB SSD of storage.; Multitasking is easy with 16GB of RAM; Equipped with a blazing fast Core i5 2.00 GHz processor.
$304.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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.