How to Capture Desktop Screenshots in Python

Complete guide to desktop screen capture in Python. Compare Python MSS, DXcam, PyAutoGUI for capturing monitors, windows, and screen regions.

Blog post 3 min read

Written by

Dmytro Krasun

Published on

If you’re looking to take screenshots of websites, you are in the wrong place—check our my website screenshots guide instead. This guide is about capturing your desktop: applications, games, or anything displayed on your screen.

Quick Comparison

LibrarySpeedCross-platformBest For
Python MSSFast (30-60 FPS)YesGeneral purpose
DXcamVery fast (240+ FPS)Windows onlyGaming/streaming
PyAutoGUISlow (1-5 FPS)YesAutomation scripts

Python MSS: The best general-purpose choice

Python MSS is my recommendation for most use cases—it’s fast, cross-platform, and reliable.

import mss
with mss.mss() as sct:
# Capture the entire screen
screenshot = sct.grab(sct.monitors[0])
# Save to file
mss.tools.to_png(screenshot.rgb, screenshot.size, output='screenshot.png')

Best for: General desktop capture on any platform.

Full mss guide →

DXcam: Maximum Performance, Windows only

For gaming, streaming, or any high-FPS application, dxcam is unbeatable on Windows.

import dxcam
camera = dxcam.create()
frame = camera.grab() # Returns numpy array
# Or continuous capture
camera.start(target_fps=60)
# ... frames available via camera.get_latest_frame()
camera.stop()

Best for: Game capture, screen recording, real-time processing.

Full dxcam guide →

PyAutoGUI: Automation first, capture second

PyAutoGUI is the easiest to use, though slower. Great for automation scripts.

import pyautogui
# Full screen
screenshot = pyautogui.screenshot()
screenshot.save('screenshot.png')
# Specific region
region_shot = pyautogui.screenshot(region=(0, 0, 500, 500))

Best for: Automation scripts, simple captures, beginners.

Full PyAutoGUI guide →

Capturing Specific Monitors

With mss

import mss
with mss.mss() as sct:
# List all monitors
for i, monitor in enumerate(sct.monitors):
print(f"Monitor {i}: {monitor}")
# Capture specific monitor (1 = first monitor)
monitor_1 = sct.grab(sct.monitors[1])
# Capture all monitors combined
all_monitors = sct.grab(sct.monitors[0])

With dxcam

import dxcam
# List available outputs
outputs = dxcam.device_info()
# Create camera for specific monitor
camera = dxcam.create(output_idx=0) # First monitor

Capturing Specific Regions

With mss

import mss
with mss.mss() as sct:
region = {
'left': 100,
'top': 100,
'width': 500,
'height': 500
}
screenshot = sct.grab(region)

With DXcam

import dxcam
camera = dxcam.create()
frame = camera.grab(region=(100, 100, 600, 600)) # left, top, right, bottom

With pyautogui

import pyautogui
# region = (left, top, width, height)
screenshot = pyautogui.screenshot(region=(100, 100, 500, 500))

Continuous Capture (Screen Recording)

With DXcam (Fastest)

import dxcam
import time
camera = dxcam.create(output_color="BGR")
camera.start(target_fps=60)
frames = []
start = time.time()
while time.time() - start < 5: # Record for 5 seconds
frame = camera.get_latest_frame()
if frame is not None:
frames.append(frame)
camera.stop()
print(f"Captured {len(frames)} frames")

With Python MSS

import mss
import time
frames = []
start = time.time()
with mss.mss() as sct:
monitor = sct.monitors[1]
while time.time() - start < 5:
frame = sct.grab(monitor)
frames.append(frame)
print(f"Captured {len(frames)} frames")

Converting to Other Formats

Python MSS to PIL Image

import mss
from PIL import Image
with mss.mss() as sct:
screenshot = sct.grab(sct.monitors[1])
img = Image.frombytes('RGB', screenshot.size, screenshot.bgra, 'raw', 'BGRX')
img.save('screenshot.png')

Python MSS to NumPy Array

import mss
import numpy as np
with mss.mss() as sct:
screenshot = sct.grab(sct.monitors[1])
img_array = np.array(screenshot) # BGRA format

DXcam Output

DXcam returns NumPy arrays directly:

import dxcam
camera = dxcam.create(output_color="RGB") # or "BGR" for OpenCV
frame = camera.grab() # Returns numpy array

Performance Benchmarks

Tested on Windows 10, 1920x1080 monitor:

LibraryFPSNotes
dxcam240+DirectX-based
mss30-60Cross-platform
PIL ImageGrab10-15Built-in
pyautogui1-5Uses PIL internally

Choosing the Right Library

Need high FPS (gaming/streaming)?
├── Yes → Use dxcam (Windows only)
└── No
├── Cross-platform needed?
│ ├── Yes → Use mss
│ └── No
│ ├── Already using PIL? → Use ImageGrab
│ └── Want automation? → Use pyautogui

Website Screenshots versus Desktop Screen Capture

As a reminder on what to use and when:

TaskUse This
Screenshot a websitePlaywright
Screenshot desktop appsPython MSS or DXcam
Record gameplayDXcam
Automate desktop tasksPyAutoGUI

If you need to capture websites, don’t use desktop capture libraries—they’ll just capture your browser window. Use proper website screenshot tools instead.

Summary

Desktop screen capture in Python:

  1. Python MSS: Best general-purpose choice (fast, cross-platform)
  2. DXcam: Best for gaming/high-FPS (Windows only)
  3. PyAutoGUI: Easiest to use (but slowest)

For website screenshots, just use Playwright for Python instead or check our guide on website screenshots in Python.

Frequently Asked Questions

If you read the article, but still have questions. Please, check the most frequently asked. And if you still have questions, feel free reach out at support@screenshotone.com.

What is the difference between desktop screen capture and website screenshots?

Desktop screen capture captures what's displayed on your monitor (any application). Website screenshots render a web page in a browser. Use Playwright/Selenium for websites, use Python MSS/DXcam for desktop capture.

What is the fastest Python screen capture library?

DXcam is fastest on Windows (240+ FPS), followed by Python MSS (30-60 FPS cross-platform). PyAutoGUI is slowest but easiest to use. Choose based on your speed requirements and platform.

How to capture a specific monitor in Python?

Use mss with the monitor parameter. mss.monitors[1] is the first monitor, mss.monitors[2] is the second, etc. mss.monitors[0] captures all monitors combined.

Read more Desktop screen capture

Interviews, tips, guides, industry best practices, and news.

View all posts
How to Take Screenshots with Python MSS

How to Take Screenshots with Python MSS

Complete guide to the MSS Python screen capture library. Learn installation, capturing monitors, regions, performance optimization, and common errors like xgetimage() failed.

Read more

Automate website screenshots

Exhaustive documentation, ready SDKs, no-code tools, and other automation to help you render website screenshots and outsource all the boring work related to that to us.