File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11build /
22.cache /
33dist /
4- MANIFEST
4+ * .egg-info /
5+ MANIFEST *
56.DS_Store
67* .orig
78* .png
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 22Examples
33========
44
5+ GNU/Linux
6+ ---------
7+
8+ Usage example with a specific display::
9+
10+ from mss.linux import MSS
11+
12+
13+ display = ':0.0'
14+ print('Screenshot of display "{0}"'.format(display))
15+ output = 'monitor{0}-%d.png'.format(display)
16+
17+ with MSS(display=display) as screenshotter:
18+ for filename in screenshotter.save(output=output):
19+ print(filename)
20+
21+
522Using PIL
623---------
724
Original file line number Diff line number Diff line change 77from os import rename
88from os .path import isfile
99
10- from mss import ScreenshotError , mss
10+ from mss import mss , ScreenshotError
1111
1212
1313def main ():
Original file line number Diff line number Diff line change 99
1010
1111def main ():
12- ''' Usage example with specified display. '''
12+ ''' Usage example with a specific display. '''
1313
1414 display = ':0.0'
15+ print ('Screenshot of display "{0}"' .format (display ))
16+
1517 try :
1618 with MSS (display = display ) as screenshotter :
17- print ('Screenshot of display "{0}"' .format (display ))
1819 output = 'monitor{0}-%d.png' .format (display )
1920 for filename in screenshotter .save (output = output ):
2021 print (filename )
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ # coding: utf-8
3+ ''' This is part of the MSS Python's module.
4+ Source: https://github.com/BoboTiG/python-mss
5+ '''
6+
7+ from mss import mss , ScreenshotError
8+ from PIL import Image
9+
10+
11+ def main ():
12+ ''' PIL example using frombytes(). '''
13+
14+ try :
15+ with mss () as screenshotter :
16+ # We retrieve monitors informations:
17+ monitors = screenshotter .enum_display_monitors ()
18+
19+ # Get rid of the first, as it represents the "All in One" monitor:
20+ for num , monitor in enumerate (monitors [1 :], 1 ):
21+ # Get raw pixels from the screen.
22+ # This method will store screen size into `width` and `height`
23+ # and raw pixels into `image`.
24+ screenshotter .get_pixels (monitor )
25+
26+ # Create an Image:
27+ size = (screenshotter .width , screenshotter .height )
28+ img = Image .frombytes ('RGB' , size , screenshotter .image )
29+
30+ # And save it!
31+ output = 'monitor-{0}.png' .format (num )
32+ img .save (output )
33+ print (output )
34+
35+ return 0
36+ except ScreenshotError as ex :
37+ print (ex )
38+
39+ return 1
40+
41+
42+ if __name__ == '__main__' :
43+ exit (main ())
You can’t perform that action at this time.
0 commit comments