def SetWallpaper(imagePath, fillType='fill'):
tile = "0"
if fillType == "tile":
fillType = "center"
tile = "1"
fillDict = {
"fill": "10",
"fit": "6",
"Stretch": "2",
"center": "0",
"span": "22"
}
style = fillDict[fillType]
key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,
r"Control Panel\Desktop", 0,
win32con.KEY_SET_VALUE)
win32api.RegSetValueEx(key, "WallpaperStyle", 0, win32con.REG_SZ, style)
win32api.RegSetValueEx(key, "TileWallpaper", 0, win32con.REG_SZ, tile)
win32gui.SystemParametersInfo(
win32con.SPI_SETDESKWALLPAPER, imagePath, 1 + 2)
# main script
python类SPI_SETDESKWALLPAPER的实例源码
def setWallPaperFromBmp(bmp):
key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER, 'Control Panel\\Desktop', 0, win32con.KEY_SET_VALUE)
win32api.RegSetValueEx(key, 'WallpaperStyle', 0, win32con.REG_SZ,'0')
win32api.RegSetValueEx(key, 'TileWallpaper', 0, win32con.REG_SZ, '0')
win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, bmp, 1+2)
def update_img(file_name):
dir_name = os.path.abspath('.')
print(dir_name)
img_path = os.path.join(dir_name, file_name)
print(img_path)
win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, img_path, 1 + 2)
# delete picture per month
def setWallpaper(self,fontsize=22,verticalspacing=26,leftmargin=800):
if self.__setimage(fontsize,verticalspacing,leftmargin)=="FilePathError":
return "FilePathError"
k = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,"Control Panel\\Desktop",0,win32con.KEY_SET_VALUE)
win32api.RegSetValueEx(k, "WallpaperStyle", 0, win32con.REG_SZ, "2")
win32api.RegSetValueEx(k, "TileWallpaper", 0, win32con.REG_SZ, "0")
win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, self.wallpaperpath, 1+2)