我正在为自己做一个小项目,但我碰壁了。我需要在 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)
最佳答案
我像这样使用 SystemParametersInfoW 而不是 SystemParametersInfoA:
ctypes.windll.user32.SystemParametersInfoW(20, 0, path, 3)
这是 ANSI 与 UNICODE 路径字符串的问题。
它适用于 Windows 10。
关于windows - 通过python更改Windows 10中的桌面背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40941167/