pywin32库版本308
–
import os
import time
import win32con
import win32gui
def set_wallpaper(image_path):
# 设置桌面壁纸
win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, image_path, win32con.SPIF_UPDATEINIFILE | win32con.SPIF_SENDCHANGE)
def change_wallpaper_every_10_seconds(folder_path):
# 获取文件夹中所有图片文件的路径
image_files = [os.path.join(folder_path, f) for f in os.listdir(folder_path) if f.endswith(('.jpg', '.jpeg', '.png', '.bmp'))]
if not image_files:
print("No image files found in the folder.")
return
# 循环更换壁纸
while True:
for image_file in image_files:
set_wallpaper(image_file)
print(f"Wallpaper changed to: {image_file}")
time.sleep(10) # 等待10秒
# 设置图片文件夹路径
folder_path = r"C:\Users\rkey\Pictures\Screenshots" # 替换为你的图片文件夹路径
change_wallpaper_every_10_seconds(folder_path)
–
发表回复