1

I've been tring to change the desktop background using Python 2.7 :

SPI_SETDESKWALLPAPER = 20
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, pngName, 0)

( While pngName is a valid path to an image )

When I run the script nothing changes, and when I try it with a different image it works just fine.

Any suggestions?

p.s. can someone please explain how that script works? I've taken it from somewhere and don't quite understand it.

Thanks!

1 Answer 1

1

Instead of using png files (I believe you're using them, given the variable name for image paths is pngName), try jpg. It seems that MS Windows doesn't support png as a background image format (As a Linux/Mac user, I cannot confirm it myself, but see this discussion for more details).

Regarding how your script works, I can briefly say that it uses ctypes Python package that allows you to call functions in dlls/shared libraries such as SystemParametersInfo. SystemParametersInfo (see MSDN page) retrieves/sets values of some system-wide parameters, including setting Desktop parameters like wallpaper file. See Example Three here for more insights.

Sign up to request clarification or add additional context in comments.

2 Comments

I appreciate your answer. Tried using both png and jpg with no luck. If i print : ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, pngName, 0) I get 0, which indicates it can't find the image if I'm not mistaken. However I triple-checked and found nothing. Any other suggestion? And thank you for the scond part. Very helpful Edit: Is it possible that it happens becuase the picture is a paint file saved as jpg? because an original photo from the same dir actually worked.
@BenL hmm, then I'd suggest to follow the discussion that I mentioned above (take a look at the first answer at least). Some people report that resizing jpg to match your screen resolution and dpi solves the problem. SystemParametersInfoA returns boolean, and 0 means it fails to set the wallpaper. To get a more specific error message, you need to use ctypes.GetLastError() (see also MSDN)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.