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)
# 一個程序就是一個進(jìn)程,進(jìn)程里面包含線程,默認(rèn)一個進(jìn)程就只有一個線程,也即單線程
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)