用Python设置桌面墙纸

网上看的一段比较好玩的代码, 利用Python设置windows系统的桌面.

原文 http://seasons.javaeye.com/blog/60294

This is a python snippet to set wallpaper as the photo of the day in national geographic.

1. install python form http://www.python.org/download/
2. install python image library(PLI) from http://www.pythonware.com/products/pil/
3. say the code below and run it by python


python 代码

"""
Set the wallpaper as the picture got from national geographic picture of the day
by
seasons@gmail.com
"""
import ctypes
import Image
import calendar
import urllib
import socket

STOREDIR = 'C:/lg_wallpaper/pod/'

def setWallpaperFromBMP(imagepath):
SPI_SETDESKWALLPAPER = 20 # According to
http://support.microsoft.com/default.aspx?scid=97142
#注意这条语句

ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, imagepath , 0) #SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE

def setWallPaper(imagePath):
"""Given a path to an image, convert it to bmp and set it as wallpaper"""
bmpImage = Image.open(imagePath)
newPath = STOREDIR + 'mywallpaper.bmp'
bmpImage.save(newPath, "BMP")
setWallpaperFromBMP(newPath)

def getPicture(fname):
sock = urllib.urlopen("
http://lava.nationalgeographic.com/pod/index.html")
htmlSource = sock.read()
sock.close()
pos1 = htmlSource.find('sm_wallpaper')
pos2 = htmlSource.find('/pod/pictures/normal')
filename = htmlSource[pos1+13:pos2-12]
fileurl = 'http://lava.nationalgeographic.com/pod/pictures/lg_wallpaper/'+filename
urllib.urlretrieve(fileurl, fname)
print 'got the picture from ' + fileurl

def setWallpaperOfToday():
filename = STOREDIR + str(calendar.datetime.date.today()) + '.jpg'
print filename
getPicture(filename)
setWallPaper(filename)

setWallpaperOfToday()
print 'Wallpaper set ok!'

转载于:https://www.cnblogs.com/yoshow/archive/2008/01/14/1038992.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值