Hi ππ
Welcome everyone! In this post, I will share with you how to change the desktop wallpaper using Python.
Step 1:
If you need any desktop wallpaper, you can download it from the internet.
Step 2
import Python modules
import win32con
import ctypes
import os
Step 3
Create a function called set_desktop_wallpaper
import win32con
import ctypes
import os
def set_desktop_wallpaper(image_path):
image_path = os.path.join(os.getcwd(), image_path)
change = win32con.SPIF_UPDATEINIFILE or win32con.SPIF_SENDCHANGE
ctypes.windll.user32.SystemParametersInfoW(win32con.SPI_SETDESKWALLPAPER, 0, image_path, 0, change)
set_desktop_wallpaper('alone.jpg')
SPIF_UPDATEΒINIΒFILE
Writes the new system-wide parameter setting to the user profile.
SPIF_SENDΒCHANGE
Broadcasts the WM_SETTINGΒCHANGE message after updating the user profile.
This info is from https://devblogs.microsoft.com/oldnewthing/20160721-00/?p=93925.
SPI_SETDESKWALLPAPER used to change the desktop wallpaper
Now we're done π€
Don't forget to like and follow π
Support me on PayPal π€
https://www.paypal.com/paypalme/amr396
Top comments (0)