A cross-platform multiple screenshots module in pure python using ctypes
Project description
Very basic, it will grab one screen shot by monitor or a screen shot of all monitors and save it to a PNG file, Python 2.6/3.5 compatible & PEP8 compliant.
MSS stands for Multiple ScreenShots.
It’s under zlib licence.
Installation
You can install it with pip:
pip install --upgrade mss
Or you may just drop it in your project and forget about it.
Support
Python |
GNU/linux |
Mac OS X |
Windows |
---|---|---|---|
3.5.0a3 |
True |
True |
True |
3.4.3 |
True |
True |
True |
3.3.6 |
True |
True |
True |
3.2.6 |
True |
True |
True |
3.1.5 |
True |
True |
True |
3.0.1 |
True |
True |
True |
2.7.9 |
True |
True |
True |
2.6.9 |
True |
True |
True |
Feel free to try MSS on a system we had not tested, and let report us by creating an [issue](https://github.com/BoboTiG/python-mss/issues).
Testing
You can try the MSS module directly from the console:
python mss.py
Instance the good class
So MSS can be used as simply as:
from mss import mss screenshotter = mss()
Or import the good one:
from mss import MSSLinux as mss screenshotter = mss()
save(output, screen, callback)
For each monitor, grab a screenshot and save it to a file.
Parameters:
output - string - the output filename. It can contain '%d' which will be replaced by the monitor number. screen - integer - grab one screenshot of all monitors (screen=-1) grab one screenshot by monitor (screen=0) grab the screenshot of the monitor N (screen=N) callback - function - in case where output already exists, call the defined callback function with output as parameter. If it returns True, then continue; else ignores the monitor and switches to ne next.
This is a generator which returns created files.
Examples
One screenshot per monitor:
for filename in screenshotter.save(): print(filename)
Screenshot of the monitor 1:
for filename in screenshotter.save(screen=1): print(filename)
Screenshot of the monitor 1, with callback:
def on_exists(fname): ''' Callback example when we try to overwrite an existing screenshot. ''' from os import rename from os.path import isfile if isfile(fname): newfile = fname + '.old' print('{0} -> {1}'.format(fname, newfile)) rename(fname, newfile) return True for filename in screenshotter.save(screen=1, callback=on_exists): print(filename)
A screenshot to grab them all:
for filename in screenshotter.save(output='fullscreen-shot.png', screen=-1): print(filename)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file mss-1.0.2.tar.gz
.
File metadata
- Download URL: mss-1.0.2.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb37bf94c6621fbbe19a6d448edcf708e121248275652bc8a1c2c89012cfacf5 |
|
MD5 | 451463038890c7c2efd1a4dd1a54bf87 |
|
BLAKE2b-256 | 3511df441b4e295cc6444f3e7c91dbc10694d278cf1b3ee3f5dfab2d6d5c07e2 |