Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > Python与其他语言

Python实现设置windows桌面壁纸代码分享

来源:中文源码网    浏览:192 次    日期:2024-05-17 16:55:26
【下载文档:  Python实现设置windows桌面壁纸代码分享.txt 】


Python实现设置windows桌面壁纸代码分享
每天换一个壁纸,每天好心情。
# -*- coding: UTF-8 -*-
from __future__ import unicode_literals
import Image
import datetime
import win32gui,win32con,win32api
import re
from HttpWrapper import SendRequest
StoreFolder = "c:\\dayImage"
def setWallpaperFromBMP(imagepath):
k = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,"Control Panel\\Desktop",0,win32con.KEY_SET_VALUE)
win32api.RegSetValueEx(k, "WallpaperStyle", 0, win32con.REG_SZ, "2") #2拉伸适应桌面,0桌面居中
win32api.RegSetValueEx(k, "TileWallpaper", 0, win32con.REG_SZ, "0")
win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER,imagepath, 1+2)
def setWallPaper(imagePath):
"""
Given a path to an image, convert it to bmp and set it as wallpaper
"""
bmpImage = Image.open(imagePath)
newPath = StoreFolder + '\\mywallpaper.bmp'
bmpImage.save(newPath, "BMP")
setWallpaperFromBMP(newPath)
def getPicture():
url = "http://photography.nationalgeographic.com/photography/photo-of-the-day/"
h = SendRequest(url)
if h.GetSource():
r = re.findall('

相关内容