SystemParametersInfo

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

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

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

不然将报错以下:spa

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

 

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

首先须要  import win32api, win32gui, win32api, Image图片

而后经过如下两个函数实现:class

 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)
相关文章
相关标签/搜索