Programer Beginner
Programer Beginner

Reputation: 1419

Change Windows 10 Background Solid Color in Python

I am aware that with ctypes.windll.user32.SystemParametersInfoW(20, 0, pathToImage, 3) I can change the wallpaper image and by setting the pathToImage to an empty string I would effectively have no image as wallpaper, thus I will see the solid background color.

My question is, How to change the solid background color?


Edit #1

Further investigating the Windows API. I found IDesktopWallpaper setbackgroundcolor() method which sounds like something that I need. However, I am not aware how to call/use it via python or command line.

Upvotes: 0

Views: 1277

Answers (1)

Tyzeron
Tyzeron

Reputation: 306

Instead of using IDesktopWallpaper, it is more simpler to use SetSysColors (from winuser.h header).

In Python, the code would look like this:

import ctypes
from ctypes.wintypes import RGB
from ctypes import byref, c_int

def changeSystemColor(color)
    ctypes.windll.user32.SetSysColors(1, byref(c_int(1)), byref(c_int(color)))

if __name__ == '__main__':
    color = RGB(255, 0, 0) # red
    changeColor(color)

As stated in your post, you can do ctypes.windll.user32.SystemParametersInfoW(20, 0, "", 3) to remove the wallpaper image, exposing the solid background color that you can set with ctypes.windll.user32.SetSysColors.

Upvotes: 2

Related Questions