-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetWallpaper.py
26 lines (23 loc) · 1.18 KB
/
SetWallpaper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import win32api, win32con, win32gui
from PIL import Image
import re,os
def SetWallpaper(imgPath):
# 打开指定注册表路径
reg_key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, win32con.KEY_SET_VALUE)
# 最后的参数:2拉伸,0居中,6适应,10填充,0平铺
win32api.RegSetValueEx(reg_key, "WallpaperStyle", 0, win32con.REG_SZ, "2")
# 最后的参数:1表示平铺,拉伸居中等都是0
win32api.RegSetValueEx(reg_key, "TileWallpaper", 0, win32con.REG_SZ, "0")
# 刷新桌面
win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, imgPath, win32con.SPIF_SENDWININICHANGE)
'''def SetWallpaper(img_path):
#把图片格式统一转换成bmp格式,并放在源图片的同一目录
img_dir = os.path.dirname(img_path)
bmpImage = Image.open(img_path)
new_bmp_path = os.path.join(img_dir,'wallpaper.bmp')
bmpImage.save(new_bmp_path, "BMP")
set_wallpaper_from_bmp(new_bmp_path)'''
def GetSystemMetricsXY():
x = win32api.GetSystemMetrics(win32con.SM_CXSCREEN) # 获得屏幕分辨率X轴
y = win32api.GetSystemMetrics(win32con.SM_CYSCREEN) # 获得屏幕分辨率Y轴
return str(x)+"x"+str(y)