gpt4 book ai didi

windows - 通过python更改Windows 10中的桌面背景

转载 作者:可可西里 更新时间:2023-11-01 10:03:51 28 4
gpt4 key购买 nike

我正在为自己做一个小项目,但我碰壁了。我需要在 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com