国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

使用Python腳本將Bing的每日圖片作為桌面的教程

2019-11-25 17:33:20
字體:
來源:轉載
供稿:網友

微軟最近出了個 必應bing 繽紛桌面,使用下來還是不錯,可以每天更換Bing首頁的北京作為壁紙,但是該軟件有個不好的地方是,安裝后桌面上會有一個搜索框出現(xiàn),很是煩人,而且不能關掉。于是出于技術考慮,想到了使用Python來實現(xiàn)這個功能。

正如很多介紹Python書中那樣,Python是中膠水語言,用在哪里都是可行的。想要使用Python給桌面設置背景只需要下個模塊安裝即可:

http://sourceforge.net/projects/pywin32/

代碼非常簡單,參考了網上一些其他人寫了代碼,具體代碼如下:
 

# -*- coding: utf-8 -*- import urllib,time,os,Image,win32gui,win32con,win32api class StealBing:  def __init__(self):  self.content = urllib.urlopen('http://cn.bing.com/').read()  self.bgImageUrl = ''  self.localFileName = ''  self.localBMPFileName = ''  def parserImageURL(self):  tempStr = self.content[self.content.index('g_img={url:')+12:]  self.bgImageUrl = tempStr[:tempStr.index('id:/'bgDiv/'')-2]  def createLocalFileName(self):  randomStr = time.strftime("%Y%m%d", time.localtime())  self.localFileName = 'D:/Bing/' + randomStr + '.jpg'  self.localBMPFileName = 'D:/Bing/' + randomStr + '.bmp'  def downloadImage(self):  if self.bgImageUrl == '':   self.parserImageURL()  if self.localFileName == '':   self.createLocalFileName()  urllib.urlretrieve(self.bgImageUrl, self.localFileName)  def updateBGImage(self):  img = Image.open(self.localFileName)  img.save(self.localBMPFileName)  os.remove(self.localFileName)  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, self.localBMPFileName , 1+2) if __name__ == '__main__': stealBing = StealBing() stealBing.downloadImage() stealBing.updateBGImage()

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 东阿县| 铁力市| 韶山市| 曲靖市| 中阳县| 乡宁县| 内黄县| 浙江省| 黄大仙区| 沙河市| 怀柔区| 朔州市| 夏邑县| 镇康县| 乐清市| 福安市| 定安县| 乐业县| 通山县| 陆丰市| 太湖县| 芜湖县| 朔州市| 衡南县| 固原市| 荆门市| 鲜城| 新宁县| 威远县| 高雄市| 渭南市| 常熟市| 库车县| 明星| 军事| 赫章县| 常州市| 德州市| 化德县| 福州市| 林甸县|