一定要在这个根目录放个图片名字的文件夹,文件夹内必须有10张jpg图片,然后还要在程序的根目录放一个1.MP3的背景音乐
import pyautogui
import time
import os
import ctypes
import pygame
import subprocess
os.system('copy .\\图片 D:\\') #将此目录的图片copy到D盘备用
pyautogui.moveTo(1920, 1070) #指针移到一边
pyautogui.hotkey('win', 'd') #组合键 清屏
#将电脑上所有图片全部隐藏
os.system('reg add "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v "NoDesktop" /d "1" /t REG_DWORD /f')
#刷新
os.system('taskkill /F /IM explorer.exe & start /MIN explorer.exe')
#播放音乐
pygame.mixer.init()
track = pygame.mixer.music.load('1.mp3')
pygame.mixer.music.play() #启动
a = 1 #赋值
#循环10次
for i in range(10):
time.sleep(4) #停留4秒
#将图片一一呈现到电脑
cmd_1 = f'reg add "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\system" /v "Wallpaper" /d "D:\\{a}.jpg" /t REG_SZ /f'
subprocess.call(cmd_1, shell=True, stdin=subprocess.PIPE)
ctypes.windll.user32.SystemParametersInfoW(20, 0, f'D:\{a}.jpg', 0) # 设置桌面壁纸
a += 1
time.sleep(5) #停留5秒
pygame.mixer.music.stop() #关闭音乐
#显示电脑桌面所有图片
os.system('reg add "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v "NoDesktop" /d "0" /t REG_DWORD /f')
#刷新
os.system('taskkill /T /F /IM explorer.exe')
os.system('start /MIN explorer')