SystemParametersInfo

Python的模块pywin32中的win32gui.SystemParametersInfo()函数

在使用win32con.SPI_SETDESKWALLPAPER设置Wallpaper时,其第二个参数为图片路径,图片必须是BMP格式。如下:

win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER,  imagepath,  1+2)

否则将报错如下:

pywintypes.error: (0, 'SystemParametersInfo', 'No error message is available')

 

在Python中设置桌面壁纸的方法如下: 

首先需要  import win32api, win32gui, win32api, Image

然后通过以下两个函数实现:

 1 def setWallpaperFromBMP(imagepath):   
 2     k = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,"Control Panel\\Desktop",0,win32con.KEY_SET_VALUE)
 3     win32api.RegSetValueEx(k, "WallpaperStyle", 0, win32con.REG_SZ, "2") #2拉伸适应桌面,0桌面居中
 4     win32api.RegSetValueEx(k, "TileWallpaper", 0, win32con.REG_SZ, "0")
 5     win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER,imagepath, 1+2)
 6     
 7     # convert jpg to bmp
 8 def setWallPaper(imagePath):
 9     bmpImage = Image.open(imagePath) 
10     newPath = imagePath.replace('.jpg', '.bmp') 
11     bmpImage.save(newPath, "BMP")
12     setWallpaperFromBMP(newPath)

 

 

转载于:https://www.cnblogs.com/iylc/p/3416832.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值