创意编程,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 ...
随机推荐
- 用js传递当前页面的url,丢失了&后面的参数 解决办法
问题:因为登陆是用ajax传值的,在哪个页面点击登陆的,登陆成功跳到再跳回那个页面,之前直接传递的是 /index_do.php?gourl=" +location.href这样传递的,但是 ...
- 在linux环境下重启oracle数据库,解决密码过期的问题
(1) 以oracle身份登录数据库,命令:su – oracle (2) 进入Sqlplus控制台,命令:sqlplus /nolog (3) 以系统管理员登录,命令:connect /as sys ...
- Database mirroring connection error 4 'An error occurred while receiving data: '10054(An existing connection was forcibly closed by the remote host.)
公司一SQL Server镜像发生了故障转移(主备切换),检查SQL Server镜像发生主备切换的原因,在错误日志中发现下面错误: Date 2019/8/31 14:09:17 ...
- Mac中 pip3 install mysqlclient 报错
主要错误提示如下: ld: library not found for -lssl clang: error: linker command failed with exit code 1 (use ...
- Download Shuttle Pro mac文件下载器使用指南
Download Shuttle Pro是适用于macOS的最强大的下载管理器和加速器.它将文件下载分为多个部分,与使用Web浏览器相比,可以提高整体下载速度.使用我们的Pro版本,您可以访问我们的新 ...
- 2017 经典的CVPR 关于ImageCaptioning论文
1. SCA-CNN: Spatial and Channel-wise Attention in Convolutional Networks for Image Captioning ...
- centos安装jdk10
下载一个jdk10文件到linux : wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=ac ...
- verilog常见错误列表
Error/Warning 来源:https://hdlbits.01xz.net/wiki/ 题目: 1.Quartus Warning 10235: Warning (): Verilog HDL ...
- CSV和JSON格式相互转换
1.为什么要进行CSV与JSON格式之间的转换 CSV格式常用于一二维数据表示和存储,他是一种纯文本形式存储表格数据的表示方式.JSON也可以表示一二维数据.在网络信息传输中,可能需要统一表示方式,因 ...
- 如何使redis中存放的都是热点数据?
当redis使用的内存超过设置的最大内存时,会触发redis的key淘汰机制,在redis3.0中的6中淘汰策略如下: (1)noeviction :不删除策略.当达到最大内存限制时,如果需要使用更多 ...