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.
Begin with importing the pyautogui library: Then call the .screenshot () method, which will return and Image object. And simply save it using any filename that works for you: And you should get a .png file in the same directory as your Python code. Below is an example of what my screenshot looks like:
This means when you want to screenshot only a monitor by itself, start at 1. Once you identify the display to capture, you can then take the screenshot using mss_instance.grab: Monitor 0 (All Together):
To take a screenshot of all displays, we can pass all_screens=True: from PIL import ImageGrab screenshot = ImageGrab.grab(all_screens=True) # Take a screenshot that includes all screens Please note that all_screens is currently only supported in Windows Now when you call screenshot.show (), you will see that multiple monitors are now displayed.
To take a screenshot, we first need to import the ImageGrab module from PIL. After we have the ImageGrab module, we can call.grab () to take a screenshot from PIL import ImageGrab screenshot = ImageGrab.grab() # Take the screenshot On Linux, you must be using PIL 7.1.0 or higher for this to work; see release notes.
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"])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With