Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persistently change Windows desktop wallpaper using python

I use the solution provided in this post to change the Windows desktop wallpaper from Python

In particular here is the code sample

import ctypes
import os
image_file = "myimage.jpg"
print("Setting the wallpaper")
SPI_SETDESKWALLPAPER = 20 
ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0,  os.path.abspath(image_file) , 0)

The problem is that the change is non persistent, in the sense that the desktop wallpaper gets reset whenever I restart my PC. How can I persistently change the Windows desktop wallpaper from Python?

I use python 3.5

like image 469
robertspierre Avatar asked Sep 10 '26 03:09

robertspierre


1 Answers

You need to call it like this

print("Setting the wallpaper")
SPI_SETDESKWALLPAPER = 20 
SPIF_UPDATEINIFILE = 1
ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, os.path.abspath(image_file) , SPIF_UPDATEINIFILE)

Also have a look at the related documentation

like image 178
robertspierre Avatar answered Sep 11 '26 17:09

robertspierre