PyQt Screen Capture
A screen capture utility that works with PyQt6, PySide6, PyQt5, PySide2, and PySide.
Features
- Cross-platform (Windows, Linux, macOS, etc.)
- Supports Python 2+
- Automatically detects available Qt bindings
- Memory-efficient screen capture using shared ndarrays in OpenCV-compatible HWC BGRX 8888 format
- Simple generator-based interface
Installation
Make sure you have PyQt6, PySide6, PyQt5, PySide2, or PySide installed.
Then install pyqt-screen-capture
:
pip install pyqt-screen-capture
Usage
Capture single frame
from pyqt_screen_capture import hwc_bgrx_8888_screen_capturer
screen_capturer = hwc_bgrx_8888_screen_capturer()
frame = next(screen_capturer)
import matplotlib.pyplot as plt
plt.imshow(frame[:, :, [2, 1, 0]])
plt.show()
Continuous capture
import cv2
from pyqt_screen_capture import hwc_bgrx_8888_screen_capturer
for frame in hwc_bgrx_8888_screen_capturer():
cv2.imshow('Screen Capture', frame[:, :, :3])
key = cv2.waitKey()
if key & 0xFF == ord('q'):
break
Caveat
You MUST use the shared ndarray between yields, as the underlying buffer is freed afterward:
from pyqt_screen_capture import hwc_bgrx_8888_screen_capturer
screen_capturer = hwc_bgrx_8888_screen_capturer()
r1 = next(screen_capturer)
r2 = next(screen_capturer)
Acknowledgments
This project modifies code automatically determining which Qt package to use from pyqtgraph, available under the MIT License
Contributing
Contributions are welcome! Please submit pull requests or open issues on GitHub.
License
This project is licensed under the MIT License. See the LICENSE file for details.