Advertisement
Najeebsk

WALLPAPER1.py

Jan 11th, 2022
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import win32api
  3. import win32con
  4. import win32gui
  5. import os
  6. import random
  7.  
  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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement