zoukankan      html  css  js  c++  java
  • python 注册表操作

    https://blog.csdn.net/xufive/article/details/104106627

    # -*- coding: utf-8 -*-
    
    import os, random
    import win32api, win32gui, win32con
    
    
    def set_wallpaper(photo_path):
        """设置壁纸"""
    
        # 1.打开注册表键
        key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER, "Control Panel\Desktop", 0, win32con.KEY_SET_VALUE)
    
        # 2.设置壁纸风格:0=居中 1=平铺 2=拉伸
        win32api.RegSetValueEx(key, "WallpaperStyle", 0, win32con.REG_SZ, "2")
    
        # 3.设置壁纸是否缩放:0=缩放 1=原图
        win32api.RegSetValueEx(key, "TileWallpaper", 0, win32con.REG_SZ, "0")
    
        # 4.设置壁纸
        win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, photo_path, 3)
    
        # 5.关闭注册表键
        win32api.RegCloseKey(key)
    
    
    def set_wallpaper_random(photo_dir):
        """随机设置壁纸"""
    
        wall_papers = list()
        for root, dirs, files in os.walk(photo_dir):
            for name in files:
                if os.path.splitext(name)[1].lower() == ".jpg":
                    wall_papers.append(os.path.join(root, name))
    
        set_wallpaper(random.choice(wall_papers))
    
    
    if __name__ == '__main__':
        # photo_path = r'D:CSDNColumndesktopalbum20200129150646.jpg'
        # set_wallpaper(photo_path)
        set_wallpaper_random(r'C:MapDownloadgooglemapssatellite1526486')
  • 相关阅读:
    【模板】Sparse-Table
    UVa 11235 Frequent values
    【模板】树状数组
    UVa 1428 Ping pong
    数学技巧
    UVa 11300 Spreading the Wealth
    UVa 11729 Commando War
    UVa 11292 Dragon of Loowater
    POJ 3627 Bookshelf
    POJ 1056 IMMEDIATE DECODABILITY
  • 原文地址:https://www.cnblogs.com/gisoracle/p/12276082.html
Copyright © 2011-2022 走看看