Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
For a screenshot of the Windows desktop, use wx.ScreenDC as the source, copy its pixels into a bitmap through wx.MemoryDC, then save the bitmap with wx.Bitmap.SaveFile. The complete pattern is:
import wx
app = wx.App(False)
screen = wx.ScreenDC()
width, height = screen.Size.Get()
bitmap = wx.Bitmap(width, height)
memory = wx.MemoryDC()
memory.SelectObject(bitmap)
memory.Blit(0, 0, width, height, screen, 0, 0)
memory.SelectObject(wx.NullBitmap)
if not bitmap.SaveFile("screenshot.png", wx.BITMAP_TYPE_PNG):
raise OSError("Could not save screenshot.png")
This captures pixels currently visible on the desktop. The target must be visible and redrawn, and multi-monitor or high-DPI layouts require care with coordinates and scale factors.
What the wxPython screenshot sequence does
A device context (DC) is wxPython’s drawing interface. The capture pipeline has four deliberate stages:
- Read the desktop: create
wx.ScreenDC(), which represents the virtual Windows screen. - Create a destination: allocate a
wx.Bitmapat least as large as the rectangle you want. - Copy pixels: select the bitmap into
wx.MemoryDCand callBlitfrom the screen DC. - Release and write: select
wx.NullBitmapbefore using the bitmap elsewhere, then callSaveFile.
SaveFile returns a Boolean. Check it and raise an error (or show a recovery message) instead of assuming the file was written.
#1 Best Overall
- 14" diagonal, 1366x768 resolution, HD BrightView LED, Glossy NON-TOUCH Display
The wxPython wiki sample reports testing with Python 3.x, wxPython 4.x and Windows 10. That statement does not establish identical behavior on every later Windows release, graphics driver, DPI-awareness mode or monitor arrangement, so validate the result on the machines you support.
Pick the device context that matches the target
| What you need | DC to use | Important behavior |
|---|---|---|
| Entire desktop or a desktop rectangle | wx.ScreenDC |
Reads the virtual screen, which can span monitors and include negative coordinates. |
| Application client area | wx.ClientDC(window) |
Represents the client area when drawing outside an EVT_PAINT handler. |
| Whole window, including decorations | wx.WindowDC(window) |
Represents the client area plus the frame and other window decorations. |
These contexts capture what is currently on screen. A covered, minimized or not-yet-redrawn window cannot reliably provide the pixels a user expects. If you need the application’s logical drawing rather than the composited desktop, render that drawing model directly into a bitmap instead of taking a screen grab.
Capture the entire desktop
This runnable script captures the size reported by the screen DC and writes a PNG in the current working directory:
Free tools Windows power users keep installed
One-click scans. No signup required.
import wx
def capture_desktop(filename: str) -> None:
app = wx.App(False)
screen = wx.ScreenDC()
width, height = screen.Size.Get()
if width <= 0 or height <= 0:
raise RuntimeError(f"Invalid screen size: {width}x{height}")
bitmap = wx.Bitmap(width, height)
memory = wx.MemoryDC()
memory.SelectObject(bitmap)
try:
copied = memory.Blit(0, 0, width, height, screen, 0, 0)
if not copied:
raise RuntimeError("The screen pixels could not be copied")
finally:
memory.SelectObject(wx.NullBitmap)
if not bitmap.SaveFile(filename, wx.BITMAP_TYPE_PNG):
raise OSError(f"Could not save {filename}")
if __name__ == "__main__":
capture_desktop("screenshot.png")
Keep the wx.App alive until the capture finishes. The memory DC must have a selected bitmap before Blit, and it should be deselected before the bitmap is saved or reused.
Capture a rectangle or one monitor
Use a source origin and a width and height for a subrectangle. The origin is not necessarily (0, 0): a monitor positioned to the left or above the primary display has negative virtual-screen coordinates.
Rank #2
- 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
import wx
def capture_region(x: int, y: int, width: int, height: int, filename: str) -> None:
if width <= 0 or height <= 0:
raise ValueError("width and height must be positive")
screen = wx.ScreenDC()
bitmap = wx.Bitmap(width, height)
memory = wx.MemoryDC()
memory.SelectObject(bitmap)
try:
if not memory.Blit(0, 0, width, height, screen, x, y):
raise RuntimeError("The requested region could not be copied")
finally:
memory.SelectObject(wx.NullBitmap)
if not bitmap.SaveFile(filename, wx.BITMAP_TYPE_PNG):
raise OSError(f"Could not save {filename}")
app = wx.App(False)
# Replace these values with the monitor or rectangle geometry you selected.
capture_region(-1920, 0, 1920, 1080, "left-monitor.png")
Determine each display’s actual geometry on the target Windows setup and pass its origin, rather than assuming the primary display starts at zero. Check the image on mixed-scale monitors; logical window coordinates and physical bitmap pixels are not guaranteed to map one-to-one in every DPI configuration.
Capture a wxPython window
Client area
For the current client-area pixels of a visible window, use wx.ClientDC. Do this outside the window’s paint handler and only after the controls have finished drawing.
Recommended Free Tools
import wx
def capture_client(window: wx.Window, filename: str) -> None:
width, height = window.GetClientSize()
if width <= 0 or height <= 0:
raise ValueError("The window has no drawable client area")
source = wx.ClientDC(window)
bitmap = wx.Bitmap(width, height)
memory = wx.MemoryDC()
memory.SelectObject(bitmap)
try:
if not memory.Blit(0, 0, width, height, source, 0, 0):
raise RuntimeError("Client-area copy failed")
finally:
memory.SelectObject(wx.NullBitmap)
if not bitmap.SaveFile(filename, wx.BITMAP_TYPE_PNG):
raise OSError(f"Could not save {filename}")
Whole window with decorations
When the frame, title bar and borders matter, substitute wx.WindowDC(window) and size the bitmap from window.GetSize():
def capture_window(window: wx.Window, filename: str) -> None:
width, height = window.GetSize()
source = wx.WindowDC(window)
bitmap = wx.Bitmap(width, height)
memory = wx.MemoryDC()
memory.SelectObject(bitmap)
try:
if not memory.Blit(0, 0, width, height, source, 0, 0):
raise RuntimeError("Window copy failed")
finally:
memory.SelectObject(wx.NullBitmap)
if not bitmap.SaveFile(filename, wx.BITMAP_TYPE_PNG):
raise OSError(f"Could not save {filename}")
A window DC still reflects displayed pixels. Another window covering part of the target, a minimized frame or a pending repaint can produce an incomplete image. For deterministic output, schedule the capture after layout and repaint work has completed, and keep the target unobscured.
Timing, repainting and event-loop safety
Take the screenshot after the frame is shown and its controls have had an opportunity to paint. In an event-driven program, call the capture from a button handler, a timer callback or another point after Show(); avoid grabbing immediately while constructing the controls. Do not call a long series of captures on the GUI thread if it makes the interface unresponsive. Queue work carefully, but keep DC use tied to the live window and its paint lifecycle.
Rank #3
- 256 GB SSD of storage.
- Multitasking is easy with 16GB of RAM
- Equipped with a blazing fast Core i5 2.00 GHz processor.
If your requirement is a report, thumbnail or test artifact rather than an exact desktop view, render the same data into an off-screen bitmap. That avoids unrelated windows, cursor movement and transient overlays that a screen DC necessarily records.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Multi-monitor and high-DPI details
wx.ScreenDC covers the virtual screen. Windows can place a secondary display at negative X or Y coordinates, so a rectangle copied from (0, 0) is not automatically “the first monitor.” Use the monitor’s real virtual-screen origin and dimensions.
wxPython documents physical and logical pixel dimensions and DC/bitmap scale factors. On a high-DPI or mixed-scale desktop:
- Keep the coordinate system used for the source DC consistent with the bitmap dimensions.
- Do not silently convert logical window sizes into physical pixel sizes without checking the active display scale.
- Test captures on the exact Windows DPI-awareness mode, wxPython build and monitor arrangement you deploy.
- Inspect text and one-pixel borders in the output; scaling mismatches usually show up there first.
The available documentation does not establish one universal pixel mapping for every Windows DPI mode, so treat scaling as a configuration to verify rather than a fixed formula.
Saving and validating the output
wx.Bitmap.SaveFile(filename, wx.BITMAP_TYPE_PNG) writes a PNG and reports success. Use an absolute path while diagnosing a missing file, because a relative path is resolved against the process’s current working directory, not necessarily the directory containing your script.
Rank #4
- 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.
- Check the Boolean return value.
- Raise or log the target path when saving fails.
- Ensure the destination directory exists and is writable.
- Deselect the bitmap from the memory DC before saving.
- Open the resulting file with an image viewer and verify its dimensions and crop.
Troubleshooting common failures
| Symptom | Likely cause | Fix |
|---|---|---|
| Black, blank or partly empty image | The window was covered, minimized or had not repainted. | Show it, wait for layout/paint completion, keep it unobscured, and capture after the event loop has processed repaint work. |
| Only the primary monitor appears | The requested rectangle used the wrong origin or size. | Use virtual-screen geometry, including negative monitor origins, and pass that rectangle to Blit. |
| Image is the wrong size on a scaled display | Logical coordinates and physical pixels were mixed. | Use dimensions from the relevant DC/display, then test under the deployed DPI-awareness and monitor configuration. |
Blit raises an error or returns false |
The bitmap was not selected, dimensions were invalid, or the source rectangle was outside the usable area. | Create a positive-size bitmap, select it into wx.MemoryDC, validate the rectangle, and deselect it in a finally block. |
SaveFile returns false |
The path is unwritable, the directory is missing or the filename is unsuitable. | Use an absolute path, create the directory, check permissions and log the return value. |
| Client capture includes unexpected content | wx.ClientDC reads current desktop pixels, not an abstract widget tree. |
Remove occlusion and transient overlays, or render the application’s drawing model into a bitmap instead. |
Performance and reliability considerations
Memory use grows with pixel count: a larger virtual desktop requires a larger bitmap and a larger copy. Capture only the needed rectangle when full-desktop images are unnecessary. Reuse a suitably sized bitmap for repeated captures, but always select and deselect it correctly and recreate it when the target dimensions change.
For repeatable automation, record the target rectangle, display arrangement, scale setting and output path alongside each image. This makes a change caused by monitor layout or DPI configuration distinguishable from a wxPython regression. Treat a screenshot as a snapshot of one desktop state, not as a guarantee that an obscured or minimized application was rendered internally.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If what you actually need is a screenshot of a public or authenticated web page rather than the Windows desktop, ScreenshotNeo provides a website screenshot API. It is not a replacement for wx.ScreenDC when you need local desktop pixels, but it avoids maintaining a browser automation stack for URL captures.
One GET request returns PNG, JPEG, WebP or PDF. The same endpoint accepts the URL and your access key:
cURL
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Python
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)
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}`);
See the ScreenshotNeo API documentation for request options. Before capture, it can accept cookie/consent banners and remove more than 60 known consent platforms, newsletter popups and chat widgets; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed as clean shots, and response headers identify the page verdict and billing status. Its MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients.
All features are included on every plan. The Free plan includes 1,000 shots per month with no card; Starter is $5 for 3,000, Growth $15 for 15,000, Pro $39 for 60,000, Scale $99 for 250,000 and Business $249 for 1,000,000. Yearly billing gives two months free. Create a free ScreenshotNeo account to start with the 1,000 monthly shots and no card.
Best Value
- 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.
FAQ
Were the wxPython examples tested on Windows 11?
The cited wxPython wiki statement names Python 3.x, wxPython 4.x and Windows 10. It does not claim testing for every later Windows release, so verify the capture on the Windows versions and display configurations you support.
Can a screen DC reproduce a hidden or minimized window?
No. A screen-based capture records currently displayed pixels. Keep the target visible and unobscured, or render the application’s own drawing model to an off-screen bitmap when visibility is not acceptable.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Why must the bitmap be deselected?
wx.MemoryDC owns the selected drawing surface while it is selected. Calling SelectObject(wx.NullBitmap) releases that surface before you save or otherwise operate on the bitmap.
Frequently Asked Questions
Were the wxPython examples tested on Windows 11?
The wxPython wiki statement names Python 3.x, wxPython 4.x and Windows 10; it does not establish testing for every later Windows release.
Can a screen DC reproduce a hidden or minimized window?
No. It records currently displayed pixels, so keep the target visible or render the application’s drawing model off-screen.
Why deselect the bitmap from wx.MemoryDC?
Call SelectObject(wx.NullBitmap) to release the drawing surface before saving or reusing the bitmap.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Quick Recap
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.

