Python cross platform compatible multi screen scre

2019-09-06 08:34发布

问题:

Python interpretor used: 2.7 (having trouble with python3.5 py2app on OSX 10.11

I am working on an interesting screenshot app using python and pygame but i am stuck at 1 screen limit since pygame doesn't seem to implicitly support multiple screens.

My problem is that right now I use pyautogui screenshot function to capture the whole screen and i open it in a pygame fullscreen window where i can modify the image and such.

I would like to know if there is a way to screenshot multiple displays at once in a cross platform compatible way. Right now i have yet to figure out how to make pyautogui screenshot any other display other than the default one

回答1:

You may wish to look into the pyscreenshot library, its a purely python library and is supposed to be crossplatform, however also has issues with the multi monitor problem.

Another method is to call a subprocess of the specific os you are using, this means calling its native ability to screenshot via command, here is an example on IOS from this stackoverflow post outlining what i mean:

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

By @Mark Setchell

Looking at the website its already on the roadmap of pyautogui to make handling multiple screens simpler so hopefully they will resolve this.

There is also a long post here outlining the issue as it currently stands with pyautogui's multi-monitor support. So unfortunately as it stands it looks like both pygame and pyautogui do not (easily) support multi-monitor screenshotting atleast without hackish type implementations if your monitor calibrations are not completely side by side as it offsets x and y values to possibly negative's.

Latestly there is yet another...as always..another python library specifically for multi monitor screenshots in python called desktopmagic. Its available here however it makes no promises of being crossplatform and infact states only that "takes screenshots on windows". So for your purpose it may not be suitable.

Anyway hope this helps in anyway or atleast gives you more options. Hope your project works out.