新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python3實(shí)現(xiàn)Win10桌面自動(dòng)切換的方法-創(chuàng)新互聯(lián)
這篇文章主要介紹Python3實(shí)現(xiàn)Win10桌面自動(dòng)切換的方法,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
得空寫了個(gè)自動(dòng)切換桌面背景圖片的小程序。再不寫python就要扔鍵盤了,對(duì)vue還有那么一點(diǎn)好感,天天php真是有夠煩。
準(zhǔn)備工作
準(zhǔn)備個(gè)文件夾放在桌面上,平時(shí)看到什么高清好圖就拽進(jìn)去。
運(yùn)行腳本
腳本如下:
#!/usr/bin/python import ctypes import osimport random import functools import schedule index = 0 def change_background(picture_path: str) -> None: ctypes.windll.user32.SystemParametersInfoW(20, 0, picture_path, 3) def get_pictures(dir_path: str) -> list: return [os.path.join(root, name) for root, dirs, files in os.walk(dir_path, topdown=False) for name in files if name.endswith('jpg') or name.endswith('png')] def log(text): def decorator(f): @functools.wraps(f) def wrap(*args, **kwargs): p = f(*args, **kwargs) print(f'{text}: {p}') return p return wrap return decorator @log(f'DESKTOP_BG_IMG switch to') def change_background_job(dir_path) -> None: if dir_path.__class__.__name__ == 'list': dir_path = dir_path[0] pictures = get_pictures(dir_path) index = random.randint(0, len(pictures) - 1) change_background(pictures[index]) return pictures[index] def scheduler(job: staticmethod, interval, arg_num, *args) -> None: if arg_num <= 0: schedule.every(interval).seconds.do(job) else: schedule.every(interval).seconds.do(job, [args[i] for i in range(arg_num)]) while True: schedule.run_pending() if __name__ == '__main__': scheduler(change_background_job, 10, 1, r'C:\Users\zenkilan\Desktop\test_pictures', 'hello', 'world')
本文標(biāo)題:Python3實(shí)現(xiàn)Win10桌面自動(dòng)切換的方法-創(chuàng)新互聯(lián)
網(wǎng)頁路徑:http://www.dlmjj.cn/article/jcppo.html