How can I change my desktop background with python?

aliva picture aliva · Dec 30, 2009 · Viewed 53.6k times · Source

How can I change my desktop background with python?

I want to do it in both Windows and Linux.

Answer

J.J. picture J.J. · Dec 30, 2009

On Windows with python2.5 or higher, use ctypes to load user32.dll and call SystemParametersInfo() with SPI_SETDESKWALLPAPER action.

For example:

import ctypes
SPI_SETDESKWALLPAPER = 20 
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, "image.jpg" , 0)