Change Windows Background from Python

前端 未结 1 1621
青春惊慌失措
青春惊慌失措 2020-12-18 00:25

Does anyone know a way to change the Windows Desktop Wallpaper with python so that the change is permanent? I have found this code

import ctypes
SPI_SETDESKW         


        
相关标签:
1条回答
  • 2020-12-18 01:17

    This solution combines several of the comments made, and works for me:

    import ctypes
    import os
    drive = "C:\\"
    folder = "images"
    image = "test.jpg"
    image_path = os.path.join(drive, folder, image)
    SPI_SETDESKWALLPAPER = 20 
    ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, image_path, 3)
    

    (Note that you should determine the absolute path to your image, and change as needed. Also convert the image to BMP if you need to use it on XP. You can easily convert the image using Pillow)

    0 讨论(0)
提交回复
热议问题