MSS API¶
Classes¶
macOS¶
-
mss.darwin.
CFUNCTIONS
¶ New in version 6.1.0.
-
mss.darwin.
cgfloat
()¶
-
class
mss.darwin.
CGPoint
¶
-
class
mss.darwin.
CGSize
¶
-
class
mss.darwin.
CGRect
¶
GNU/Linux¶
-
mss.linux.
CFUNCTIONS
¶ New in version 6.1.0.
-
mss.linux.
PLAINMASK
¶
-
mss.linux.
ZPIXMAP
¶
-
class
mss.linux.
Display
¶ Structure that serves as the connection to the X server, and that contains all the information about that X server.
-
class
mss.linux.
Event
¶ XErrorEvent to debug eventual errors.
-
class
mss.linux.
XFixesCursorImage
¶ Cursor structure
-
class
mss.linux.
XImage
¶ Description of an image as it exists in the client’s memory.
-
class
mss.linux.
XRRCrtcInfo
¶ Structure that contains CRTC information.
-
class
mss.linux.
XRRModeInfo
¶
-
class
mss.linux.
XRRScreenResources
¶ Structure that contains arrays of XIDs that point to the available outputs and associated CRTCs.
-
class
mss.linux.
XWindowAttributes
¶ Attributes for the specified window.
Methods¶
-
mss.base.
lock
¶ New in version 6.0.0.
-
class
mss.base.
MSSBase
¶ The parent’s class for every OS implementation.
-
cls_image
¶
-
compression_level
¶ PNG compression level used when saving the screenshot data into a file (see
zlib.compress()
for details).New in version 3.2.0.
-
with_cursor
¶ Include the mouse cursor in screenshots.
New in version 8.0.0.
-
__init__
(compression_level=6, display=None, max_displays=32, with_cursor=False)¶ Parameters: New in version 8.0.0:
compression_level
,display
,max_displays
, andwith_cursor
, keyword arguments.
-
close
()¶ Clean-up method.
New in version 4.0.0.
-
grab
(region)¶ Parameters: monitor (dict) – region’s coordinates. Return type: ScreenShot
Retrieve screen pixels for a given region. Subclasses need to implement this.
Note
monitor can be a
tuple
likePIL.Image.grab()
accepts, it will be converted to the appropriatedict
.
-
save
([mon=1][, output='mon-{mon}.png'][, callback=None])¶ Parameters: Return type: iterable
Returns: Created file(s).
Grab a screen shot and save it to a file. The output parameter can take several keywords to customize the filename:
{mon}
: the monitor number{top}
: the screen shot y-coordinate of the upper-left corner{left}
: the screen shot x-coordinate of the upper-left corner{width}
: the screen shot’s width{height}
: the screen shot’s height{date}
: the current date using the default formatter
As it is using the
format()
function, you can specify formatting options like{date:%Y-%m-%s}
.Warning
On Windows, the default date format may result with a filename containing ‘:’ which is not allowed:
IOerror: [Errno 22] invalid mode ('wb') or filename: 'sct_1-2019-01-01 21:20:43.114194.png'
To fix this, you must provide a custom date formatting.
-
-
class
mss.base.
ScreenShot
¶ Screen shot object.
Note
A better name would have been Image, but to prevent collisions with
PIL.Image
, it has been decided to use ScreenShot.-
classmethod
from_size
(cls, data, width, height)¶ Parameters: Return type: Instantiate a new class given only screen shot’s data and size.
-
classmethod
-
mss.tools.
to_png
(data, size, level=6, output=None)¶ Parameters: Raises: - ScreenShotError – On error when writing data to output.
- zlib.error – On bad compression level.
Dump data to the image file. Pure Python PNG implementation. If output is
None
, create no file but return the whole PNG data.New in version 3.0.0.
Changed in version 3.2.0: The level keyword argument to control the PNG compression level.
Properties¶
-
class
mss.base.
MSSBase
¶ -
monitors
¶ Positions of all monitors. If the monitor has rotation, you have to deal with it inside this method.
This method has to fill
self._monitors
with all information and use it as a cache:self._monitors[0]
is a dict of all monitors togetherself._monitors[N]
is a dict of the monitor N (with N > 0)
Each monitor is a dict with:
left
: the x-coordinate of the upper-left cornertop
: the y-coordinate of the upper-left cornerwidth
: the widthheight
: the height
Subclasses need to implement this.
Return type: list[dict[str, int]]
-
-
class
mss.base.
ScreenShot
¶ -
__array_interface__
¶ Numpy array interface support. It uses raw data in BGRA form.
Return type: dict[str, Any]
-
pos
¶ The screen shot’s coordinates.
Return type: collections.namedtuple()
-
size
¶ The screen shot’s size.
Return type: collections.namedtuple()
-
Exception¶
-
exception
mss.exception.
ScreenShotError
¶ Base class for MSS exceptions.
-
details
¶ On GNU/Linux, and if the error comes from the XServer, it contains XError details. This is an empty dict by default.
For XErrors, you can find information on Using the Default Error Handlers.
Return type: dict[str, Any] New in version 3.3.0.
-