没啥好说的,论坛很多以bing做壁纸的,再补上Python版本的- #**************
- #coding=utf-8
- #by ivor
- #设置bing.com背景为壁纸
-
-
-
- import re
- import requests
- import pythoncom
- from win32com.shell import shell, shellcon
-
-
- class MyPaper:
-
- def __init__(self):
- self.image = r"C:\paper.jpg"
- self.url = r'https://cn.bing.com/'
-
- def getDeskComObject(self):
- self.g_desk = None
- if not self.g_desk:
- self.g_desk = pythoncom.CoCreateInstance(shell.CLSID_ActiveDesktop, \
- None, pythoncom.CLSCTX_INPROC_SERVER, \
- shell.IID_IActiveDesktop)
- return self.g_desk
-
- def setWallPaper(self):
- self.desktop = self.getDeskComObject()
- if self.desktop:
- self.desktop.SetWallpaper(self.image, 0)
- self.desktop.ApplyChanges(shellcon.AD_APPLY_ALL)
-
- def addUrlLink(self, lnk):
- self.desktop = self.getDeskComObject()
- self.desktop.AddUrl(0, lnk, 0, 0)
-
- def imgDownload(self):
- r = requests.get(self.url).content
- pattern = re.compile(r'url: "(.*jpg)?')
- imgUrl = re.findall(pattern,r.decode(encoding="utf-8"))
-
- imgData = requests.get(self.url + imgUrl[0]).content
- with open(self.image ,"wb") as file:
- file.write(imgData)
-
-
- setPaper = MyPaper()
- setPaper.imgDownload()
- setPaper.setWallPaper()
复制代码
|