本文定期更换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 : intSystem parameter to query or set, one of the SPI_GET* or SPI_SET* constants
Param=None : objectdepends on action to be taken
WinIni=0 : intFlags 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/intAn already open key, or any one of the following win32con constants:
HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
subKey : stringThe 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 : intReserved. Must be zero.
sam=KEY_READ : intSpecifies 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, win32condef setWallPaper(pic):# open registerregKey = 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 screenwin32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER,pic, win32con.SPIF_SENDWININICHANGE)setWallPaper('E:\\backPics\\character5.jpg')

效果:

接下来,我们设定每隔一个小时换一次壁纸
我的图库中只有5张图片,所以显示图片的标志只能在[1 - 5]中循环了。

import Image
import win32api, win32gui, win32con
import timedef setWallPaper(pic):# open registerregKey = 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 screenwin32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER,pic, win32con.SPIF_SENDWININICHANGE)g_times = 0
while True:g_times = g_times+1g_times = g_times%5picDir = 'E:\\backPics\\character'picDir = picDir+str(g_times+1)+'.jpg'setWallPaper(picDir)time.sleep(60*60)

python 更换windows壁纸(简单)相关推荐

  1. python 更换桌面壁纸 播放音乐

    python 改桌面壁纸 播放音乐 - win10可用. 注意: 1)打开 想关闭 直接关机 或者等自动关机 ,本程序无害,由python3编写并由 pyinstaller 打包 2)会在 c盘创建个 ...

  2. 用python更换桌面壁纸

    windows自带幻灯片壁纸功能,但我发现它有时会导致一个叫"Shell Infrastructure Host"的进程占用大量CPU资源.为了平衡一个阿宅对CPU和二次元的需求, ...

  3. python写动态壁纸_10分钟教你用python更换电脑壁纸

    注:本文转载自公众号:木白瞎说 大家好,非常抱歉因为作者懒癌晚期好久没更新(也实在是没写什么值得分享的东西),今天就来诈尸一下(●'◡'●) 今天也没有表情包当引子了,因为做图真的好麻烦啊orz(你说 ...

  4. 用python当壁纸_python实现windows壁纸定期更换功能

    本文定期更换windows壁纸的python程序,很简单,属于自己写着玩的那种,不提供完美的壁纸切换解决方案. 安装pywin32 extensions 安装python2.7后,然后管理员的方式运行 ...

  5. 爬虫bing的图片,近千张,下载后自动更换为windows壁纸

    爬虫bing的图片,下载后自动更换为windows壁纸 由于百度的广告太多了,就用了一段时间bing.com搜索,发现每次打开背景大图都很漂亮,而且每次切换,于是就想把它下载下来,作为桌面背景,也是很 ...

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

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

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

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

  8. python修改桌面壁纸_利用Python对windows桌面自动更换壁纸

    根据时间星期几判断用哪张壁纸 # !/usr/bin/env python3 # -*- coding:utf-8 -*- import requests # import pywintypes im ...

  9. 利用Python自动更换电脑壁纸

    公众号后台回复"图书",了解更多号主新书内容 作者:叶庭云,https://blog.csdn.net/fyfugoyfa 一.前言 美桌网里有大量的高清图片素材和壁纸,并且可以免 ...

最新文章

  1. javascript 回调函数
  2. R----plotly包介绍学习
  3. jquery php cookie,jQuery的Cookie插件 cookie 使用方法
  4. android menu分割线,给 NavigationView 的Menu的分割线 设置高度和颜色
  5. Java笔记之对象代理实例
  6. 【优化预测】基于matlab飞蛾扑火算法优化LSSVM预测【含Matlab源码 142期】
  7. aud删除 oracle_Oracle 11g如何清理数据库的历史日志详解
  8. DEV C++下载,百度云盘,干净
  9. 飞机大战python素材_python飞机大战源码和素材
  10. JS同步执行延时函数的实现
  11. mapgis6.7的放大缩小快捷键
  12. 巧用JMP公式,让新变量的生成更简单
  13. 基于华为云ModelArts(实现垃圾分类识别)
  14. html制作一个视频播放器,H5 打造属于自己的视频播放器(HTML 篇)
  15. PHP等比缩放并补白
  16. Codeforces868F Yet Another MinimizationProblem
  17. docker安装nginx镜像
  18. 自学python接单_用Python在网上接单,兼职也可以月薪过万
  19. MySQL死锁产生的原因和解决方法
  20. mybatis整合sqlite

热门文章

  1. 2015软件设计师考试(英语部分)
  2. TOLUA的文件结构
  3. 怎样用计算机打出祝你前程似锦,祝你前程似锦作文600字
  4. 北邮计算机考研多少分上岸,北京邮电大学考研分享:初试327分上岸,338分放弃复试!...
  5. 对英雄联盟比赛预测(三)- 数据获取Java实现
  6. JS 实现数字转罗马数字
  7. [转载]轻松学习XML(六)
  8. 中国仪表板市场趋势报告、技术动态创新及市场预测
  9. .shtml网站解析UnicodeError
  10. 判断ssh远程命令是否执行结束