Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import win32api
- import win32con
- import win32gui
- import os
- import random
- import shutil
- # set the picture as the desktop background and refer to the address https://blog.csdn.net/zwvista/article/details/18655
- def setWallpaper(image_path):
- key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,"Control Panel\\Desktop",0,win32con.KEY_SET_VALUE)
- win32api.RegSetValueEx(key, "WallpaperStyle", 0, win32con.REG_SZ, "2")
- win32api.RegSetValueEx(key, "TileWallpaper", 0, win32con.REG_SZ, "0")
- win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER,image_path, 1+2)
- # get the names and reference addresses of all files in the specified directory https://blog.csdn.net/zhuzuwei/article/details/79925562
- filePath = 'C:\\Windows\\Web\\Wallpaper\\'
- test = os.listdir(filePath+"WALLP\\")
- # randomly take a value from the list of obtained picture names and set it to wallpaper , reference https with random value ://blog.csdn.net/weixin_39791387/article/details/84958436?utm_medium=distribute.pc_relevant_download.none-task-blog-baidujs-1.nonecase&depth_1-utm_source=distribute.pc_relevant_download.none-task-blog-baidujs-1.nonecase
- image_path = random.choice(test)
- setWallpaper(filePath+"WALLP\\"+image_path)
- # move the set picture to another folder, refer to https://blog.csdn.net/silentwolfyh/article/details/74931123
- shutil.move(filePath+"WALLP\\"+image_path, filePath+"ok\\")
- print(" set successfully ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement