========
Examples
========
Basics
======
One screen shot per monitor
---------------------------
::
for filename in sct.save():
print(filename)
Screen shot of the monitor 1
----------------------------
::
filename = sct.shot()
print(filename)
A screen shot to grab them all
------------------------------
::
filename = sct.shot(mon=-1, output='fullscreen.png')
print(filename)
Callback
--------
Screen shot of the monitor 1 with a callback:
.. literalinclude:: examples/callback.py
:lines: 8-
Part of the screen
------------------
You can capture only a part of the screen:
.. literalinclude:: examples/part_of_screen.py
:lines: 8-
.. versionadded:: 3.0.0
Part of the screen of the 2nd monitor
-------------------------------------
This is an example of capturing some part of the screen of the monitor 2:
.. literalinclude:: examples/part_of_screen_monitor_2.py
:lines: 8-
.. versionadded:: 3.0.0
Use PIL bbox style and percent values
-------------------------------------
You can use the same value as you would do with ``PIL.ImageGrab(bbox=tuple(...))``.
This is an example that uses it, but also using percentage values:
.. literalinclude:: examples/from_pil_tuple.py
:lines: 8-
.. versionadded:: 3.1.0
PNG Compression
---------------
You can tweak the PNG compression level (see :py:func:`zlib.compress()` for details)::
sct.compression_level = 2
.. versionadded:: 3.2.0
Advanced
========
You can handle data using a custom class:
.. literalinclude:: examples/custom_cls_image.py
:lines: 8-
.. versionadded:: 3.1.0
PIL
===
You can use the Python Image Library (aka Pillow) to do whatever you want with raw pixels.
This is an example using `frombytes()