使用python持久更改Windows桌面墙纸

2024-05-15 22:47:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用thispost中提供的解决方案从Python更改Windows桌面墙纸

这里是代码示例

import ctypes
import os
image_file = "myimage.jpg"
print("Setting the wallpaper")
SPI_SETDESKWALLPAPER = 20 
ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0,  os.path.abspath(image_file) , 0)

问题是这种改变是非持久性的,从某种意义上说,每当我重新启动电脑时,桌面墙纸都会被重置。我如何从Python持续更改Windows桌面墙纸?在

我使用python3.5


Tags: 代码imageimportspi示例oswindows解决方案
1条回答
网友
1楼 · 发布于 2024-05-15 22:47:06

你应该这样称呼它

print("Setting the wallpaper")
SPI_SETDESKWALLPAPER = 20 
SPIF_UPDATEINIFILE = 1
ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, os.path.abspath(image_file) , SPIF_UPDATEINIFILE)

同时看看相关的documentation

相关问题 更多 >