创意编程,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 ...
随机推荐
- 45-管理 Machine
用 docker-machine 创建 machine 的过程很简洁,非常适合多主机环境.除此之外,Docker Machine 也提供了一些子命令方便对 machine 进行管理.其中最常用的就是无 ...
- ORACLE 12.2RAC之问题 ora.chad OFFLINE
问题描述: 早上巡检是发现一套RAC的ora.chad一个节点的状态是offline,其他的均正常. crsctl stat res -t ora.chad ONLINE ...
- [Go] 轻量服务器框架tcp的粘包问题 封包与拆包
tcp传输的数据是以流的形式传输的,因此就没有办法判断到哪里结束算是自己的一个消息,这样就会出现粘包问题,多个包粘在一起了 可以使用这样一个自定义的形式来解决,一个消息分为 head+body he ...
- python的安装以及前景
1.检查软件是否安装:在cmd命令行上输oython 假如环境已经配置好环境变量 则会显示为python的inf: 2.下载并安装python 打开python官网:https://www.pytho ...
- js之好看的鼠标点击-光标特效
1.光标特效 <script src="https://blog-static.cnblogs.com/files/axqa/bubbleCursor.js">< ...
- slave_master_info和slave_relay_log_info中的Master_log_pos不一致
最近在研究mysql的主从,发现一个问题,我在主库做任何修改时,在从库中只有slave_relay_log_info中的Master_log_pos在变化,而slave_master_info中的Ma ...
- 【AGC035F】Two Histograms
Problem Description 你有一个 \(N\) 行.\(M\) 列的.每个格子都填写着 0 的表格.你进行了下面的操作: 对于每一行 \(i\) ,选定自然数 \(r_i\) (\(0\ ...
- 【编译系统02】编译器 - 语义分析器(semantic)的简单设计思路(变量类与变量表)
当我们分析到 "int n;",说明其已经定义了一个变量,之后又遇到一个 "n=3",我们从哪里去找这个n并且赋值呢? 答案是:通过我们定义的 变量表(Tabl ...
- mesos-slave启动不起来
刚开始时候的状态 后来装了docker后
- 文本分类Pipeline