导语
Hello,大家好!我是木木子!
今天闲着闲着——发现电脑的壁纸用了百八十年了,几个月都没换了。想着在有时间的时候换下壁纸换下心情✨!
大家是不是经常换壁纸都是下载一个壁纸的软件往下拉的?
或者都是只能一张一张的单独更换,如果我们可以设定电脑的壁纸按照你的时间随时更换那不是更好,那每天起来上班
的时候一瞬间都能看到自己喜欢的壁纸,新的壁纸,满满的好心情有没有?
那么,go go go !!! 到了该换壁纸的时候啦!
赶快跟着木木子一起动手做一款随自己心意的专属自动换电脑壁纸的神器吧!每天拥有好心情
正文
每天都是自己喜欢的壁纸——心情真的超级好滴!
一、首先
1)素材
准备好自己喜欢的壁纸图片哦,指定的图片都放在Pictures的文件夹里面如下所示:
注意:壁纸可以随意修改的哈。
2)环境
本文的话是代码挺简单的都是些自带的模块,依旧用的以前的版本运行代码的。
二、config.xml设置
config.xml设置的是定时更新桌面壁纸的时间,大家可随意设置修改。
<?xml version="1.0" ?> <config> <path>pictures</path> <random_time>3</random_time> </config>
三、正式敲代码
1)导入模块
import random import ctypes import time import os from xml.dom.minidom import parse import datetime
2)随机图片
def random_pic_index() : return picture_list[random.randint(0, len(picture_list)-1)]
3)读XML配置
def read_xml() : doc = parse('./config.xml') root = doc.documentElement global path, random_time path = root.getElementsByTagName('path')[0].firstChild.data random_time = int(root.getElementsByTagName('random_time')[0].firstChild.data) #print(path, random_time)
4)替换壁纸
def main() : read_xml() if not init_pic() : print('Init error, not have pictures(filename with .jpg)') exit (1) while True : filename = random_pic_index() ctypes.windll.user32.SystemParametersInfoW(20, 0, build_path([path, filename]), 0) #替换壁纸 print('%s picture: %s' %(datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S'), filename)) time.sleep(random_time)
完整的项目源码去主页源码基地领取哈!
四、效果展示视频
这里小编只准备了3张图片,大家可以多准备点儿滴。
Python自动换壁纸神器!每天都是好心情!
总结
”快乐的一天从换壁纸开始“!
嘿嘿,准备好了!跟我一起换换壁纸,换换心情吧~
记得三连的啦~关注小编私信06即可免费获取源码,获取更多精彩内容!
还没有评论,来说两句吧...