python实现windows壁纸定期更换功能
作者:theArcticOcean 发布时间:2022-09-06 15:05:11
本文定期更换windows壁纸的python程序,很简单,属于自己写着玩的那种,不提供完美的壁纸切换解决方案。
安装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)
来源:https://blog.csdn.net/theArcticOcean/article/details/78239904
猜你喜欢
- microtime() 函数返回当前 Unix 时间戳的微秒数。用于检测程序执行时间的函数,也是PHP内置的时间函数之一,在PHP中可以用于
- 可实现功能:1.随机生成一个整数。2.随机生成任意范围内的一个整数。3.随机生成指定长度的整数组4.随机生成指定长度的任意范围的整数组5.随
- 前言优雅关机就是服务端关机命令发出后不是立即关机,而是等待当前还在处理的请求全部处理完毕后再退出程序,是一种对客户端友好的关机方式。而执行C
- 序言这次玩次狠得。除了编译器使用yum安装,其他全部手动编译。哼~看似就Nginx、PHP、MySql三个东东,但是它们太尼玛依赖别人了。没
- 在右键菜单中加入复制目标文件的有效存放路径(单斜杠或者双反斜杠)引言由于win10电脑自带的获取文件路径为双引号括起来的单反斜杠,如下图。&
- 文 | 闲欢来源:Python 技术「ID: pythonall」今天在浏览知乎时,发现一个有趣的问题:如何优化 Python 爬
- reflect反射首先,我们要区分两个概念——“标识名”和&
- 1. 栗子为了加深大家的印象,首先我们来看个例子:图示如下:2. 矩形计算面积我们知道,在数学中,积分运算表示上述曲线和x轴围成的封闭区域的
- Python语言中import的使用很简单,直接使用 import module_name 语句导入即可。这里我主要写一下"imp
- 这篇文章主要讲TensorFlow中的Session的用法以及Variable。Session会话控制Session是TensorFlow为
- Pattern.split方法详解/** * 测试Pattern.split方法 */ @Test public void testPatt
- 项目背景 在之前的一个项目中用Python的Flask写了一个提供公共基础服务的Rest应用,上面大佬的意思是需要将这一部分封装成容器化服
- 本文实例讲述了python在控制台输出进度条的方法。分享给大家供大家参考。具体实现方法如下:进度条效果如下所示:|#############
- 近期对数据库进行巡检,发现数据库业务用户(非 SYS/Public)下存在失效对象。对失效对象进行分析,主要包括失效的视图、物化视图、函数、
- 新版Django在admin后台直接删除一条数据时,file = models.FileField(upload_to=‘file'
- 首先说说什么是内存泄露,在一个进程中,如果某一块内存无法访问,且直到进程结束为止也无法释放,那么就发生了内存泄露。通常这种情况发生在C++之
- 众所周知,IE 6只支持单通道的PNG图片(即只有透明/不透明2种状态,gif图片的透明单通道透明),因此如果需要使用alpha透明的png
- 老师罚学生抄写英文单词,结果学生给抄成这样……
- jQuery由美国人John Resig创建,至今已吸引了来自世界各地的众多javascript高手加入其team,包括来自德国的J&
- 在《JavaScript语言精粹》的第72页有这样一段:用正则表达式字面量创建的RegExp对象来共享同一个单实例:function mak