您好,登錄后才能下訂單哦!
這篇文章主要介紹python如何實現windows壁紙定期更換功能,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
安裝pywin32 extensions
安裝python2.7后,然后管理員的方式運行cmd,進入python的scripts目錄,我的是
C:\Python27\Scripts
cd /d C:\Python27\Scripts
然后敲入:python pywin32_postinstall.py -install(先確保在環境變量PATH中設置好了python.exe的目錄)
C:\Python27\Scripts>python pywin32_postinstall.py -install Copied pythoncom27.dll to C:\Windows\SysWOW64\pythoncom27.dll Copied pythoncomloader27.dll to C:\Windows\SysWOW64\pythoncomloader27.dll Copied pywintypes27.dll to C:\Windows\SysWOW64\pywintypes27.dll Registered: Python.Interpreter Registered: Python.Dictionary Registered: Python -> Software\Python\PythonCore\2.7\Help[None]=None -> Software\Python\PythonCore\2.7\Help\Pythonwin Reference[None]='C:\\Python27\\ Lib\\site-packages\\PyWin32.chm' Pythonwin has been registered in context menu Shortcut for Pythonwin created Shortcut to documentation created The pywin32 extensions were successfully installed.
這樣,pywin32就完成了安裝。
安裝PIL
PIL即是Python Image Lib。
在網上下載PIL: http://www.pythonware.com/products/pil/。我下載的是PIL-1.1.7.win32-py2.7.exe,雙擊運行即可。
注:如果要使用pip安裝,那么命令行中輸入的不是pip,而是pip2.7,如下:
C:\Python27\Scripts>pip2.7 install
You must give at least one requirement to install (see "pip help install")
關鍵函數
下面的函數幫助信息都能在PyWin32.chm中看見。
win32gui.SystemParametersInfo
SystemParametersInfo(Action, Param, WinIni) Queries or sets system-wide parameters. This function can also update the user profile while setting a parameter. Parametersundefined Action : int System parameter to query or set, one of the SPI_GET* or SPI_SET* constants Param=None : object depends on action to be taken WinIni=0 : int Flags specifying whether change should be permanent, and if all windows should be notified of change. Combination of SPIF_UPDATEINIFILE, SPIF_SENDCHANGE, SPIF_SENDWININICHANGE
win32api.RegOpenKeyEx
PyHKEY = RegOpenKeyEx(key, subKey, reserved , sam ) Opens the specified key. Parametersundefined key : PyHKEY/int An already open key, or any one of the following win32con constants: HKEY_CLASSES_ROOT HKEY_CURRENT_USER HKEY_LOCAL_MACHINE HKEY_USERS subKey : string The name of a key that this method opens. This key must be a subkey of the key identified by the key parameter. If key is one of the predefined keys, subKey may be None. In that case, the handle returned is the same key handle passed in to the function. reserved=0 : int Reserved. Must be zero. sam=KEY_READ : int Specifies an access mask that describes the desired security access for the new key. This parameter can be a combination of the following win32con constants: KEY_ALL_ACCESS KEY_CREATE_LINK KEY_CREATE_SUB_KEY KEY_ENUMERATE_SUB_KEYS KEY_EXECUTE KEY_NOTIFY KEY_QUERY_VALUE KEY_READ KEY_SET_VALUE KEY_WRITE
程序
接下來就是coding:
set.py:
import Image import win32api, win32gui, win32con def setWallPaper(pic): # open register regKey = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,"Control Panel\\Desktop",0,win32con.KEY_SET_VALUE) win32api.RegSetValueEx(regKey,"WallpaperStyle", 0, win32con.REG_SZ, "2") win32api.RegSetValueEx(regKey, "TileWallpaper", 0, win32con.REG_SZ, "0") # refresh screen win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER,pic, win32con.SPIF_SENDWININICHANGE) setWallPaper('E:\\backPics\\character5.jpg')
效果:
接下來,我們設定每隔一個小時換一次壁紙:
我的圖庫中只有5張圖片,所以顯示圖片的標志只能在[1 - 5]中循環了。
import Image import win32api, win32gui, win32con import time def setWallPaper(pic): # open register regKey = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,"Control Panel\\Desktop",0,win32con.KEY_SET_VALUE) win32api.RegSetValueEx(regKey,"WallpaperStyle", 0, win32con.REG_SZ, "2") win32api.RegSetValueEx(regKey, "TileWallpaper", 0, win32con.REG_SZ, "0") # refresh screen win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER,pic, win32con.SPIF_SENDWININICHANGE) g_times = 0 while True: g_times = g_times+1 g_times = g_times%5 picDir = 'E:\\backPics\\character' picDir = picDir+str(g_times+1)+'.jpg' setWallPaper(picDir) time.sleep(60*60)
以上是“python如何實現windows壁紙定期更換功能”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。