Skip to main content

A cross-platform multi-screen shot 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 an optimised/progressive PNG/JPEG file, Python 2.7/3.3 compatible.

So, while you can pip install mss, you may just drop it in your project and forget about it.

MSS stands for Multi-Screen Shot.

It’s under zlib licence.

Instance the good class

You can determine automatically which class to use:

from platform import system
from mss import *

systems = {
    'Darwin' : MSSMac,
    'Linux'  : MSSLinux,
    'Windows': MSSWindows
}
try:
    MSS = systems[system()]
except KeyError:
    err = 'System "{0}" not implemented.'.format(system())
    raise NotImplementedError(err)

Or simply import the good one:

from mss import MSSLinux as MSS

init(debug=False)

When initalising an instance of MSS, you can enable debug output:

mss = MSS(debug=True)

save(output=’mss’, oneshot=False, ext=’png’, ftype=0)

For each monitor, grab a screen shot and save it to a file.

Parameters:

output - string - the output filename without extension
oneshot - boolean - grab only one screen shot of all monitors
ext - string - file format to save
ftype - int - PNG filter type (0..4 [slower])

This is a generator which returns created files:

'output-1.ext',
'output-2.ext',
...,
'output-NN.ext'
or
'output-full.ext'

Example

Then, it is quite simple:

try:
    mss = MSS()

    # One screen shot per monitor
    for filename in mss.save():
        print('File "{0}" created.'.format(filename))

    # A shot to grab them all :)
    for filename in mss.save(oneshot=True):
        print('File "{0}" created.'.format(filename))
except Exception as ex:
    print(ex)
    raise

Bonus

Just for fun … Show us your screen shot with all monitors in one file, we will update the gallery.

Link to the galley: https://tiger-222.fr/tout/python-mss/galerie/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mss-0.0.2.tar.gz (10.3 kB view details)

Uploaded Source

File details

Details for the file mss-0.0.2.tar.gz.

File metadata

  • Download URL: mss-0.0.2.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mss-0.0.2.tar.gz
Algorithm Hash digest
SHA256 6e4ea86946dc7337ba14a05567134066d98fdc8a69eb12c8d1fcb56b554a6074
MD5 8c8821ff4b1798c7838a02192f04e4ad
BLAKE2b-256 ee32d4b0ee5f85a13188a8481f22a1fe8abc78ff611f37a9da2848ab0379730a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page