本文定期更换windows壁纸的python程序,很简单,属于自己写着玩的那种,不提供完美的壁纸切换解决方案。

安装pywin32 extensions

安装python2.7后,然后管理员的方式运行cmd,进入python的scripts目录,我的是

C:\Python27\Scriptscd /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当壁纸_python实现windows壁纸定期更换功能相关推荐

  1. python修改电脑桌面壁纸_python实现桌面壁纸切换功能

    本文实例为大家分享了python实现桌面壁纸切换功能的具体实现方法,供大家参考,具体内容如下 大体分为两个部分 一.利用爬虫爬取壁纸 第一部分爬取图片url地址并且下载至本地 爬虫针对http://i ...

  2. python修改桌面壁纸_python实现桌面壁纸切换功能

    本文实例为大家分享了python实现桌面壁纸切换功能的具体实现方法,供大家参考,具体内容如下 大体分为两个部分 一.利用爬虫爬取壁纸 第一部分爬取图片url地址并且下载至本地 爬虫针对http://i ...

  3. python程序员专用壁纸_Python开发专属壁纸下载与轮换程序

    本人对于壁纸一直偏佛系,不爱特意去找一堆壁纸.因此用Python简单地搞了一个自动下载壁纸,定时随机轮换的功能来自娱自乐,顺便分享给大家. 原文链接:https://www.codernice.top ...

  4. python专属壁纸_Python开发专属壁纸下载与轮换程序

    本人对于壁纸一直偏佛系,不爱特意去找一堆壁纸.因此用Python简单地搞了一个自动下载壁纸,定时随机轮换的功能来自娱自乐,顺便分享给大家. 原文链接:查看 准备 下载安装Python3 官网下载即可, ...

  5. python命令ipad锁屏_python实现windows倒计时锁屏功能

    python实现windows倒计时锁屏功能 # 倒计时锁屏 import time from ctypes import * def closewindows(closetime): while c ...

  6. python修改电脑桌面壁纸_python设置windows桌面壁纸的方法

    #!/usr/bin/env python # -*- coding: UTF-8 -*- #----------------------------------------------------- ...

  7. python修改桌面壁纸_python设置windows桌面壁纸

    #!/usr/bin/env python # -*- coding: UTF-8 -*- #----------------------------------------------------- ...

  8. python代码桌面壁纸_python设置windows桌面壁纸的实现代码

    #!/usr/bin/env python # -*- coding: UTF-8 -*- #----------------------------------------------------- ...

  9. python修改桌面壁纸_python设置windows桌面壁纸的实现代码

    #!/usr/bin/env python # -*- coding: UTF-8 -*- #----------------------------------------------------- ...

最新文章

  1. conda不是内部或外部命令
  2. 《OpenGL ES 3.x游戏开发(下卷)》一1.2 顶点数组对象
  3. python降维效果图_python实现拉普拉斯特征图降维示例
  4. 20211231 使用windows 10代理时,快捷设置“手动设置代理”的“不使用代理”条目
  5. 通过key登录ssh
  6. Dalvik/ART(ANDROID)中的多线程机制(4)
  7. Dart 1(环境安装)
  8. Android 中发送短信
  9. JMeter使用总结
  10. mysql时间返回整小时_MySql 时间处理
  11. Android ListView 指定显示最后一行
  12. Oracle中登录OEM口令忘记,oracle oem创建过程 一直提示sys密码错误
  13. ref:使用Dezender对zend加密后的php文件进行解密
  14. matlab 调和级数作图,华工数学实验报告斐波那契数列.doc
  15. cyclone4驱动LM75A温湿度传感器学习
  16. 硬件工程师需要掌握什么基础知识
  17. ALG:应用层网关(防火墙)
  18. kalilinux安装中文输入法 安装fcitx,小企鹅输入法。
  19. CRM实战分类以及对企业运营的思考
  20. Oracle数据库字段翻译

热门文章

  1. 汕头大学应用数学硕士专业
  2. 苹果Apple Watch可检测自行车是否有助力,苹果Find My助力市场
  3. Google Static Maps API
  4. 在安装软件时,出现:系统管理员设置了系统策略,禁止进行此项安装 怎么办
  5. 利用transmac在windows上做启动U盘
  6. DM spoke-to-spoke
  7. 诺基亚EnodeB关于空口参考信号功率 计算和验证方法
  8. 基于MOS缓启动电路笔记
  9. 和python有关的工作_“学会了Python,我的人生跟开挂一样!”
  10. 强化学习-Q-learning FrozenLake-V0 实现