Advertisement
Najeebsk

WALLPAPER2.py

Jan 11th, 2022
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.44 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import win32api
  3. import win32con
  4. import win32gui
  5. import os
  6. import random
  7. import shutil
  8.  
  9. # set the picture as the desktop background and refer to the address https://blog.csdn.net/zwvista/article/details/18655
  10. def setWallpaper(image_path):
  11.     key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,"Control Panel\\Desktop",0,win32con.KEY_SET_VALUE)
  12.     win32api.RegSetValueEx(key, "WallpaperStyle", 0, win32con.REG_SZ, "2")
  13.     win32api.RegSetValueEx(key, "TileWallpaper", 0, win32con.REG_SZ, "0")
  14.     win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER,image_path, 1+2)
  15.  
  16. # get the names and reference addresses of all files in the specified directory https://blog.csdn.net/zhuzuwei/article/details/79925562
  17. filePath = 'C:\\Windows\\Web\\Wallpaper\\'
  18. test = os.listdir(filePath+"WALLP\\")
  19.  
  20. # 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
  21. image_path = random.choice(test)
  22. setWallpaper(filePath+"WALLP\\"+image_path)
  23.  
  24. # move the set picture to another folder, refer to https://blog.csdn.net/silentwolfyh/article/details/74931123
  25. shutil.move(filePath+"WALLP\\"+image_path, filePath+"ok\\")
  26.  
  27. print(" set successfully ")
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement