python代码桌面壁纸_Python实现设置windows桌面壁纸代码

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

发布于 2015-04-07 16:59:42 | 122 次阅读 | 评论: 0 | 来源: 网友投递

Python编程语言Python 是一种面向对象、解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年。Python语法简洁而清晰,具有丰富和强大的类库。它常被昵称为胶水语言,它能够把用其他语言制作的各种模块(尤其是C/C++)很轻松地联结在一起。

每天换一个壁纸,每天好心情。

# -*- 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('

你可能感兴趣的:(python代码桌面壁纸)