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开发多功能壁纸自动切换工具!的更多相关文章

  1. TriAquae 是一款由国产的基于Python开发的开源批量部署管理工具

    怀着鸡动的心情跟大家介绍一款国产开源运维软件TriAquae,轻松帮你搞定大部分运维工作!TriAquae 是一款由国产的基于Python开发的开源批量部署管理工具,可以允许用户通过一台控制端管理上千 ...

  2. pip:带你认识一个 Python 开发工作流程中的重要工具

    摘要:许多Python项目使用pip包管理器来管理它们的依赖项.它包含在Python安装程序中,是Python中依赖项管理的重要工具. 本文分享自华为云社区<使用Python的pip管理项目的依 ...

  3. python开发_tkinter_菜单选项中英文切换_菜单选项不可用操作_博主推荐

    我使用的python版本为:3.3.2 如果你对python中tkinter模块的菜单操作不是很了解,你可以看看: python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推 ...

  4. Ubuntu 设定壁纸自动切换的shell脚本

    升级到Ubuntu14.04后,感觉bug的确比12.04少多了.顶部任务栏支持半透明效果,所以整个桌面也看上去漂亮了很多.这样的桌面也是值得瞎捣鼓一下的,想到换壁纸,但是没找到设定动态更换壁纸的选项 ...

  5. python开发必备神器 Virtualenv及管理工具Virtualenvwrapper

    如果在一台机器上,想开发多个不同的项目,需要用到同一个包的不同版本,如果还在本地继续安装,在同一个目录下安装或者更新,其它的项目必须就无法运行了,怎么办呢? 解决方案:虚拟环境 虚拟环境可以搭建独立的 ...

  6. python开发_platform_获取操作系统详细信息工具

    ''' python中,platform模块给我们提供了很多方法去获取操作系统的信息 如: import platform platform.platform() #获取操作系统名称及版本号,'Win ...

  7. js轮播功能 标签自动切换 同页面多轮播js

    需要加入jquery 1.43及以上版本 下面还有个简单版,一个页面只支持一个轮播 同页面多轮播js <div> <div class="yt_content"& ...

  8. iOS开发之实现图片自动切换(类似android画廊效果)

    #import ViewController.h #define ImageViewCount 5   @interface ViewController ()<uiscrollviewdele ...

  9. Python开发【第一篇】:目录

    本系列博文包含 Python基础.前端开发.Web框架.缓存以及队列等,希望可以给正在学习编程的童鞋提供一点帮助!!! Python开发[第一篇]:目录 Python开发[第二篇]:初识Python ...

随机推荐

  1. SolrCloud 高可用集群搭建

    1.1 什么是SolrCloud SolrCloud(solr 云)是Solr提供的分布式搜索方案,当你需要大规模,容错,分布式索引和检索能力时使用 SolrCloud.当一个系统的索引数据量少的时候 ...

  2. 数据库迁移导致Unknown character set: 'GBK' 应用异常

    https://blog.csdn.net/u013415591/article/details/82692242https://blog.csdn.net/gx_1_11_real/article/ ...

  3. pytest系列(一):什么是单元测试界的高富帅?

    pytest是python语言中一款强大的单元测试框架,用来管理和组织测试用例,可应用在单元测试.自动化测试工作中. unittest也是python语言中一款单元测试框架,但是功能有限,没有pyte ...

  4. Eureka集群

    Eureka集群搭建 高可用集群配置 当注册中心扛不住高并发的时候,这时候 要用集群来扛: 普通操作 我们再新建两个module  microservice-eureka-server-2002  m ...

  5. Python元组是什么

    引出 在使用Python过程中,列表.集合和字典是比较常用的数据结构. 列表简单说就是数组,不对,它就是数组 集合就是去重的元素结构,和JAVA中的set一样 字典就是一个key-value的键值对, ...

  6. canvas绘制线条详解

    canvas详解----绘制线条 <!DOCTYPE html> <html> <head> <title>canvas详解</title> ...

  7. 【搬了一套别人的cf】

    自己打了一堆没保存瞬间全没了.... 没有继续写的欲望 https://www.cnblogs.com/tea-egg/p/11664350.html

  8. linux-在指定路径下查询文件夹是否存在

    我们常常在Linux下去查找文件 find / -name 'test.py' # 在根目录下查找名为test.py的文件 但是如果用查找文件的方式去查找文件夹的话,是查不到的 find / -max ...

  9. java8-CompleableFuture的使用1

    背景 硬件的极速发展,多核心CPU司空见惯:分布式的软件架构司空见惯: 功能API大多采用混聚的方式把基础服务的内容链接在一起,方便用户生活. 抛出了两个问题: 如何发挥多核能力: 切分大型任务,让每 ...

  10. 在windows桌面上创建一个文件夹

    用dos命令创建 md [文件路径][文件名] C:\Users\admin>md  C:\Users\admin\desktop\test 刷新一下桌面,就可以看见桌面上创建了一个名为test ...