M
M
Maxim Zubenko2021-02-25 20:59:32
Python
Maxim Zubenko, 2021-02-25 20:59:32

How to set different wallpapers on different monitors in Windows?

Hello!
The question is not really about python, but rather about win32 api.

All this on Windows 10 64 bit. Here is the code that sets a random wallpaper on the desktop (everything is shortened, but even in this version it works):

import ctypes
import random
import os

start_path = "D:/_Картинки клиппарды обои"
list_images = os.listdir(start_path)
img_path = os.path.join(start_path, random.choice(list_images))

ctypes.windll.user32.SystemParametersInfoW(20, 0, img_path, 0)


Everything is working. But I have two monitors and the same picture is put on these two monitors. If you do it manually, then I can put a different picture on different monitors. How to do it programmatically through python?

my comment disappeared somewhere, I hope it doesn't disappear here again:
I found a microsoft manual page where IDesktopWallpaper::SetWallpaper is called. But I still don’t understand in which DLL it’s all in, so that you can connect via python.
guide is here .
Maybe someone will tell you what code to use instead of ctypes.windll.user32. SystemParametersInfoW(20, 0, img_path, 0)
To write something like:
ctypes.windll.???.IDesktopWallpaper.SetWallpaper(1, img_path)
ctypes.windll.???.IDesktopWallpaper.SetWallpaper(2, img_path2)


added. Maybe someone will help to compile a DLL with the functionality of IDesktopWallpaper, or maybe there is already one and tell me where to download it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question