import time
import pygame
import win32api
import win32con
import win32gui
import threading # 线程模块
def go():
pygame.mixer.init()
while True:
for i in range(5):
filePath = r"C:\Users\Administrator\Desktop\python知识点\res2"+"\\"+str(i)+".mp3"
track = pygame.mixer.music.load(filePath)
pygame.mixer.music.play()
time.sleep(15)
pygame.mixer.music.stop()
def setWallPaper(path):
reg_key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, win32con.KEY_SET_VALUE)
win32api.RegSetValueEx(reg_key, "WallpaperStyle", 0, win32con.REG_SZ, "6")
win32api.RegSetValueEx()
win32api.RegSetValueEx(reg_key, "WallPaper")
win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, path, win32con.SPIF_SENDWININICHANGE)
# 一个程序就是一个进程,进程里面包含线程,默认一个进程就只有一个线程,也即单线程
th = threading.Thread(target=go, name="LoopThread")
th.start()
while True:
for i in range(9):
filePath = r"C:\Users\Administrator\Desktop\python知识点\res2"+"\\"+str(i)+".jpg"
setWallPaper(filePath)
time.sleep(2)