Changing Windows background with Python

Does anyone know a way to change windows desktop wallpaper using python so that the changes are permanent? I found this code

import ctypes SPI_SETDESKWALLPAPER = 20 ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, "myimage.jpg" , 0) 

This code works, but as soon as you log out and log back in, the background returns to the original image. I would prefer a solution that does not require registry editing, and I would like something that works with Windows XP and 7, if possible.

+6
source share
1 answer

This solution combines several comments made and works for me:

 import ctypes import os drive = "C:\\" folder = "images" image = "test.jpg" image_path = os.path.join(drive, folder, image) SPI_SETDESKWALLPAPER = 20 ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, image_path, 3) 

(Note that you must determine the absolute path to your image and change as necessary. Also convert the image to BMP if you need to use it on XP. You can easily convert the image using a pad )

+1
source

Source: https://habr.com/ru/post/946604/


All Articles