Hello, no one knows how to set the wallpaper by means of python? OS - Win7, if it matters.
2 answers
import os User=str(os.getenv('USERPROFILE')) os.system(r'''reg add "hkcu\Control panel\desktop" /v wallpaper /d "'''+ User+r'\Local Settings\Application Data\Microsoft\Wallpaper1.bmp" /f') os.system(r'''reg add "hkcu\Control panel\desktop" /v WallpaperStyle /d 2 /f''') os.system(r'''RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True''')
- In general, it works, but for some reason not always. I have a simple script that selects a random * .jpg file and installs it on the wallpaper in the way you specify. Three or four times in a row it works, then it stops. By what principle - not yet understood. I can only say for sure that it is not random that randomly selects the same file several times, I checked this possibility. What can it be, don't you know? - R_cassum
|
Here is an example of a script that changes the desktop background:
def set_wallpaper(path): import ctypes cs = ctypes.c_buffer(path.encode()) SPI_SETDESKWALLPAPER = 0x14 return ctypes.windll.user32.SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, cs, 0) set_wallpaper(r'C:\wall.jpg')
I used an algorithm here - a script that downloads satellite imagery and sets it as a desktop background every half hour
- While I was dealing with this topic then, there were some actions with the registry, but it seems that this script doesn’t need to be done - gil9red
- 1- Try SystemParametersInfoW to support non-ASCII paths 2- see if you need the last parameter to be set (instead of zero):
SPIF_UPDATEINIFILE |SPIF_SENDWININICHANGE
(1 | 2) - jfs *W()
should be used directly withpath
(Unicode). In general, it is not clear why it did not break withcs
(bytes). - jfs- I'll return ka back for now: D there is no time to test and desire) - gil9red
|