创意编程,Python开发多功能壁纸自动切换工具!
import ctypes
import time
import requests
import os
from threading import Thread
from tkinter import Tk, Label, Button,Entry,StringVar,messagebox
# r'C:\Users\86156\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup'
# '放到AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup下把本文件后缀设为pyw 就会开机自启'
class Bz(object):
def __init__(self):
self.curent_url = 'https://tenapi.cn/img/acg.php'
self.root = Tk()
self.root.attributes("-alpha", 0.8)
self.root.title('Python学习交流群:127341871')
self.root.geometry('218x55+1300+20')
self.b1 = Button(self.root, text=' 换一类 ', command=self.change_type, fg='#00f235',width=8).place(x=0, y=0)
self.b2 = Button(self.root, text='下一张>> 频率(分)', command=self.change_next, fg='blue',width=22).place(x=63, y=0)
self.b3 = Button(self.root, text='停止切换', command=self.stop, fg='red', width=8).place(x=0, y=30)
self.label = Label(self.root, text='二次元',fg='#9e3dff')
self.label.place(x=85, y=30)
e = StringVar()
self.input=Entry(self.root,textvariable=e,fg='#ffaf0a')
e.set(0.1) #默认0.1分钟 6s
self.input.place(x=153, y=30)
self.url_list = {1: ['影视', 'http://pic.tsmp4.net/api/yingshi/img.php'],
2: ['随机', 'http://lorempixel.com/1920/1080/'],
3: ['女神', 'http://pic.tsmp4.net/api/nvsheng/img.php'],
4: ['风景', 'http://pic.tsmp4.net/api/fengjing/img.php'],
5: ['二次元', 'https://tenapi.cn/img/acg.php']}
self.path = 'D:\壁纸'
self.filepath = self.path + '/img.jpg'
if not os.path.exists(self.path):
os.makedirs(self.path)
self.flag = True
self.start = 1
def stop(self):
self.flag = False
def change_type(self):
if self.start > 5:
self.start = 1
list = self.url_list.get(self.start)
curent_type = list[0]
self.curent_url = list[1]
self.label['text'] = curent_type
self.start += 1
def change_next(self):
data = requests.get(url=self.curent_url).content
with open(self.filepath, 'wb') as f:
f.write(data)
self.config()
def get_img(self):
try:
self.num = eval(self.input.get()) * 60 #捕获结束界面后的异常
except Exception:
pass
try:
data = requests.get(url=self.curent_url).content
with open(self.filepath, 'wb') as f:
f.write(data)
time.sleep(self.num) # 睡眠单位秒
self.config()
except Exception:
pass
def config(self):
ctypes.windll.user32.SystemParametersInfoW(20, 0, self.filepath, 0) # 设置桌面壁纸.
def img(self):
while self.flag:
self.get_img()
def run(self):
t1 = Thread(target=self.img)
# t1.setDaemon(True) #设置守护线程 --->是否完全关闭
t1.start()
self.root.mainloop()
if self.flag:
root = Tk()
root.withdraw()
messagebox.showinfo("Python学习交流群:127341871", "只关闭了界面! 图片还在切换! 请进入任务管理器结束进程")
if __name__ == '__main__':
b = Bz()
b.run()

创意编程,Python开发多功能壁纸自动切换工具!的更多相关文章
- TriAquae 是一款由国产的基于Python开发的开源批量部署管理工具
怀着鸡动的心情跟大家介绍一款国产开源运维软件TriAquae,轻松帮你搞定大部分运维工作!TriAquae 是一款由国产的基于Python开发的开源批量部署管理工具,可以允许用户通过一台控制端管理上千 ...
- pip:带你认识一个 Python 开发工作流程中的重要工具
摘要:许多Python项目使用pip包管理器来管理它们的依赖项.它包含在Python安装程序中,是Python中依赖项管理的重要工具. 本文分享自华为云社区<使用Python的pip管理项目的依 ...
- python开发_tkinter_菜单选项中英文切换_菜单选项不可用操作_博主推荐
我使用的python版本为:3.3.2 如果你对python中tkinter模块的菜单操作不是很了解,你可以看看: python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推 ...
- Ubuntu 设定壁纸自动切换的shell脚本
升级到Ubuntu14.04后,感觉bug的确比12.04少多了.顶部任务栏支持半透明效果,所以整个桌面也看上去漂亮了很多.这样的桌面也是值得瞎捣鼓一下的,想到换壁纸,但是没找到设定动态更换壁纸的选项 ...
- python开发必备神器 Virtualenv及管理工具Virtualenvwrapper
如果在一台机器上,想开发多个不同的项目,需要用到同一个包的不同版本,如果还在本地继续安装,在同一个目录下安装或者更新,其它的项目必须就无法运行了,怎么办呢? 解决方案:虚拟环境 虚拟环境可以搭建独立的 ...
- python开发_platform_获取操作系统详细信息工具
''' python中,platform模块给我们提供了很多方法去获取操作系统的信息 如: import platform platform.platform() #获取操作系统名称及版本号,'Win ...
- js轮播功能 标签自动切换 同页面多轮播js
需要加入jquery 1.43及以上版本 下面还有个简单版,一个页面只支持一个轮播 同页面多轮播js <div> <div class="yt_content"& ...
- iOS开发之实现图片自动切换(类似android画廊效果)
#import ViewController.h #define ImageViewCount 5 @interface ViewController ()<uiscrollviewdele ...
- Python开发【第一篇】:目录
本系列博文包含 Python基础.前端开发.Web框架.缓存以及队列等,希望可以给正在学习编程的童鞋提供一点帮助!!! Python开发[第一篇]:目录 Python开发[第二篇]:初识Python ...
随机推荐
- 从零开始搭建solo个人博客系统
目录 1.博客系统的搭建流程 2.服务器选购 2.1阿里云学生主机 2.2普通云主机 3.域名购买与备案(可选) 3.1域名购买 3.2域名服务器备案 3.3域名服务器解析 4.solo安装 4.1 ...
- Docker 常用操作命令
一. docker安装 方式1 本地安装: 1)下载docker安装文件: 2)执行安装命令 yum localinstall *: 3)安装完之后 重启 systemctl restart do ...
- 设置自动获取IP和DNS
问题阐述 设置ipv4的自动获取时遇到一个问题,ip和dns自动获取可以确认设置,但是全局时就是报错,回头去看ipv4的ip和dns也还是原来的样子 由于一直使用的都是自动获取,很少会有主动设置ip或 ...
- Red Hat Enterprise Linux 官方正式版镜像下载
Red Hat Enterprise Linux是美国红帽公司开发的商业市场导向的Linux发行版,为方便大家学习研究,整理分享历代红帽官方正式版镜像给有需要的朋友们. 下载地址:https://ww ...
- QT QSplitter设置初始比例setStretchFactor失效解决
QSplitter如下为常用 设置显示比例 pRightSplitter=new QSplitter(Qt::Vertical); pRightSplitter->setMouseTrackin ...
- PowerMock学习(八)之Mock Argument Matcher的使用
前言 本计划在上周六日将powermock学完,并同步到博客中,结果自己没经得住诱惑,又开始去打王者荣耀了.虽然两天时间我从钻石一升到了星耀V四星,但是我并没有觉得很开心,相反很失落呢.不得不说腾讯的 ...
- Mybatis中返回Map
在Mybatis中,我们通常会像下边这样用: 返回一个结果 User selectOne(User user); <select id="selectOne" paramet ...
- ubuntu18.04 安装 QQ
参照大佬文章https://www.lulinux.com/archives/1319 我将安装过程需要的命令行总结出来,便于直接快速安装. # 安装 wine git clone https://g ...
- 线程队列queue的使用
其实线程队列queue跟进程Queue的用法一样. 一.先进先出 import queue q = queue.Queue() q.put('kobe') q.put('cxk') print(q.g ...
- MVC过滤器:自定义操作过滤器
一.操作过滤器 1.定义 操作过滤器用于实现IActionFilter接口以及包装操作方法执行.IActionFilter接口声明两个方法:OnActionExecuting和OnActionExec ...