Creative programming, Python development tools multi-functional automatic switching wallpaper!

ctypes Import 
Import Time 
Import Requests 
Import os 
from the Thread Threading Import 
from Tkinter Import Tk, the Label, the Button, the Entry, StringVar, MessageBox 
# r'C: \ the Users \ 86156 \ AppData \ Roaming \ in the Microsoft \ Windows \ Start Menu \ Programs \ the Startup ' 
#' into the AppData \ Roaming \ Microsoft \ Windows \ under Start Menu \ Programs \ startup put this file extension to pyw will boot from Kai ' 
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 (' learning the Python exchange group: 127 341 871 ') 
        Self .root.geometry ( '218x55 + 1300 + 20 ')
        self.b1 = Button (self.root, text = ' a class of transducers', Command = self.change_type, FG = '# 00f235', width =. 8) .place (X = 0, Y = 0) 
        self.b2 = Button (self.root, text = 'at a frequency >> (min)', Command = self.change_next, FG = 'Blue', width = 22 is) .place (= 63 is X, Y = 0) 
        self.b3 = Button (self.root, text = 'stop switching', = Command, self.stop, FG = 'Red', width =. 8) .place (X = 0, Y = 30) 
        self.label the Label = (self.root , text = 'second element', FG = '# 9e3dff') 
        self.label.place (X = 85, Y = 30) 
        E = StringVar () 
        self.input = the Entry (self.root, textvariable = E, FG = '# ffaf0a') 
        e.set (0.1) # 0.1 minutes default 6S 
        self.input.place (X = 153, Y = 30) 
        self.url_list = {. 1: [ 'video', 'http: //pic.tsmp4 .net / api / yingshi / img.php '], 
                         2: [ 'random', 'http://lorempixel.com/1920 / 1080 / '], 
                         3: [' goddess ',' http://pic.tsmp4.net/api/nvsheng/img.php '], 
                         . 4: [' landscape ',' http: //pic.tsmp4. NET / API / Fengjing / img.php '], 
                         . 5: [' second element ',' 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 # after the capture end interface anomalies 
        the except Exception: 
            Pass 
        the try: 
            Data = requests.get (URL = self.curent_url) .content
            with open(self.filepath, 'wb') as f:
                f.write (Data) 
            the time.sleep (self.num) # sleep in seconds 
            self.config () 
        the except Exception: 
            Pass 
 
    DEF config (Self): 
        ctypes.windll.user32.SystemParametersInfoW (20 is, 0, self.filepath, 0 ) # set the desktop wallpaper. 
 
    DEF img (Self): 
        the while self.flag: 
            self.get_img () 
 
    DEF RUN (Self): 
        T1 = the thread (target = self.img) 
        # t1.setDaemon (True) # daemon thread - -> is totally closed 
        t1.start () 
        self.root.mainloop () 
        iF self.flag: 
            the root = Tk () 
            root.withdraw ()
            messagebox.showinfo ( "Python learning exchange group: 127 341 871", "just shut up shop image still go to the end of the switch Task Manager process!!") 
IF __name__ == '__main__': 
    b = Bz () 
    b.run ( )

  

 

 

Guess you like

Origin www.cnblogs.com/7758520lzy/p/11971333.html