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

标签 windows python-3.x windows-10

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

相关文章:

c++ - Windows 上的蓝牙低功耗低速率?

linux - 如何使用 python 3.x 运行程序

python-3.x - Python 套接字属性

python-3.x - 如何根据日期时间约束从另一个数据帧中提取行?

c++ - IVssBackupComponents::InitializeForBackup 失败

windows - 无论 Windows 版本如何,.exe 文件的默认图标

windows - 将数组传递给 x86 asm 中的函数

Windows 10 相当于 LaunchAdvancedAssociationUI

windows - 如何检索 LAN 适配器 MAC 地址?

wpf - 系统无效操作异常: 'Dispatcher processing has been suspended, but messages are still being processed.'