通过python在windows 10中更改桌面背景
问题描述:
我正在为自己开发一个小型项目,并且我碰到了一堵墙。我需要在Windows 10 64位上更改桌面背景。我试图使用下面的脚本来改变基于本地图像的背景。代码执行时没有错误,但桌面只是变黑。我加倍检查,我的图像在c:\CuratedWallpaper\Mario.bmp
,所以这不是问题。通过python在windows 10中更改桌面背景
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)
答
我用SystemParametersInfoW代替SystemParametersInfoA这样的:
ctypes.windll.user32.SystemParametersInfoW(20, 0, path, 3)
这是ANSI的UNICODE VS路径字符串的问题。
它适用于我在Windows 10中。
你能解释你使用的最后一个参数吗? – finngu