dutt
dutt

Reputation: 8209

Take screenshot of multi-monitor setup

I'm taking a screenshot using this line

screen = QPixmap.grabWindow(QApplication.desktop().winId())

but apparently that doesn't grab the full desktop if the user has several monitors.

Is there a way to grab the desktop of all monitors into a single image?

Upvotes: 4

Views: 1279

Answers (2)

PyHP3D
PyHP3D

Reputation: 88

Just need to loop over QApplication.screens() and grab them one at a time like so...

Note: using Python 3.8 and PyQt5

import os
from PyQt5.QtWidgets import QApplication

app = QApplication(sys.argv)
for screen in QApplication.screens():
    screen_path = os.path.expanduser(f"~/Desktop/{screen.name()}.jpg")
    screen.grabWindow(0).save(screen_path, 'jpg')  
    # grabWindow(0) means full screen
    # for area use following format; x=0, y=0, w=-1, h=-1

Upvotes: 0

baysmith
baysmith

Reputation: 5202

According to this blog, just add the x, y, width, and height to grab the full desktop.

Upvotes: 1

Related Questions