Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change my desktop background with python?

How can I change my desktop background with python?

I want to do it in both Windows and Linux.

like image 335
aliva Avatar asked Dec 30 '09 00:12

aliva


People also ask

Can you change the desktop background if yes how?

Click on Personalization, which is fourth from the bottom on the list. 4. Click on Background. The background page will come up which allows you to preview your background picture and lets you choose from several photos or your own photos for your desktop background.


2 Answers

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) 
like image 63
J.J. Avatar answered Sep 26 '22 01:09

J.J.


For Python3.5, SystemParametersInfoA doesn't work. Use SystemParametersInfoW.

import ctypes ctypes.windll.user32.SystemParametersInfoW(20, 0, "absolute path" , 0) 
like image 31
mesksr Avatar answered Sep 26 '22 01:09

mesksr