我正在为自己做一个小项目,我撞墙了。我需要在Windows 10 64位上更改桌面背景。我试图使用下面的脚本根据本地图像更改背景。代码执行没有错误,但桌面只是变黑。我仔细检查过,我的图片位于c:\CuratedWallpaper\Mario.bmp
,所以这不是问题。
import ctypes
directory = "c:\CuratedWallpaper"
imagePath = directory + "\Mario.bmp"
def changeBG(imagePath):
SPI_SETDESKWALLPAPER = 20
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, imagePath , 0)
return;
changeBG(imagePath)
答案 0 :(得分:2)
我使用SystemParametersInfoW而不是SystemParametersInfoA,如下所示:
ctypes.windll.user32.SystemParametersInfoW(20, 0, path, 3)
这是ANSI vs UNICODE路径字符串的问题。
它适用于Windows 10。