Take screenshot of second monitor with python on O

2019-06-18 03:46发布

问题:

I am trying to make an ambient light system with Python. I have gotten pyscreenshot to save a screenshot correctly, but I can't figure out how to get it to screenshot my second monitor (if this is even possible).

Is there a way to take a screenshot of my second monitor in Python using pyscreenshot (or something else)? I am using OSX Yosemite if that makes any difference.

回答1:

Use the built-in screencapture command and pass it 2 filenames. I believe it lives in /usr/sbin/screencapture so the command will look like this:

/usr/sbin/screencapture screen1.png screen2.png

I assume you know how to shell out to it using the subprocess module, along these lines

from subprocess import call
call(["/usr/sbin/screencapture", "screen1.png", "screen2.png"])


回答2:

Mark Setchell's answer is correct. Also this can't be done with pyscreenshot directly. If you look at the source, you'll notice that on Mac OSX they do use the screencapture utility but only pass it one file as an argument. The documentation (man screencapture) says that you have to pass in as many files as there are screens:

files – where to save the screen capture, 1 file per screen