A
A
Alikhan2021-11-09 10:18:27
Python
Alikhan, 2021-11-09 10:18:27

How to take a screenshot of the desktop in Python?

How to take a screenshot of the desktop in Python on Windows? Not a screenshot of the screen, namely the desktop. That is, we can do anything on the computer, and the program will take a screenshot of the desktop without windows of various applications, and so on. That is, a normal screenshot of the desktop without other garbage.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-11-09
@Vindicar

Well technically it is possible, but problematic.
WinAPI allows you to get a screenshot of a window with a specified handle using a series of GetDC() -> CreateCompatibleDC() -> BitBlt() calls. Getting through to Winapy from Python is tedious, but really, the pywin32 package will help.
The problem is that the desktop can consist of more than one window - for example, the background can be separate, and the icons can be separate. This depends at least on the version of Windows, and may even change within the same version (this is the basis of the trick that allows you to put the application window UNDER the icons).
You have to determine the windows that belong to the desktop, get their handles, take screenshots of them, and then bring them together somehow.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question