壁纸轮播小工具,每xxx秒后自动切换壁纸;
新人练手,大佬勿喷!{:301_998:}
import os
import ctypes
from time import sleep
from random import randint
def map_storage(path):
file_list = []
picture_list = os.listdir(path)
for line in picture_list:
# 壁纸过滤 - 只保留图像文件格式
try:
if line.split('.')[1] == 'png' or line.split('.')[1] == 'jpeg' or line.split('.')[1] == 'jpg':
file_list.append(path + '\\' + line)
except:
pass
# print('壁纸总数:', len(file_list), '张')
return file_list
def random_wallpaper(image_path):
# 随机抽出一张壁纸
image_path = image_path[randint(0, len(image_path) - 1)]
# 设置壁纸
ctypes.windll.user32.SystemParametersInfoW(20, 0, image_path, 3)
print('设置成功...')
if __name__ == '__main__':
user_path = input('请输入壁纸文件夹路径(绝对路径): ')
file_path = map_storage(user_path)
while True:
# 设置定时切换壁纸
random_wallpaper(file_path)
sleep(5)
|