Changing desktop background with Python

血红的双手。 提交于 2021-01-29 02:44:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!