问题
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:
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.
来源:https://stackoverflow.com/questions/34292004/changing-desktop-background-with-python