【发布时间】:2016-10-28 21:01:11
【问题描述】:
我在 SO 和 Google 上尝试了每个示例,但没有一个有效。我不知道为什么,脚本完成没有任何错误。但背景图像不会改变。我为该图像设置了绝对路径,我尝试了jpg,png 格式,基本上我尝试了所有方法,但所有示例都完成了,没有任何错误,但背景图像没有改变。有一个可行的例子吗? Windows-7 Python 3.4
有些例子没有用;
import ctypes
SPI_SETDESKWALLPAPER = 20
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, "myimage.jpg" , 0)
########################################
#This example can't find images, but I put absolute path to it. Don't know what's the problem
import struct
import ctypes
SPI_SETDESKWALLPAPER = 20
WALLPAPER_PATH = 'C:\\your_file_name.jpg'
def is_64_windows():
"""Find out how many bits is OS. """
return struct.calcsize('P') * 8 == 64
def get_sys_parameters_info():
"""Based on if this is 32bit or 64bit returns correct version of SystemParametersInfo function. """
return ctypes.windll.user32.SystemParametersInfoW if is_64_windows() \
else ctypes.windll.user32.SystemParametersInfoA
def change_wallpaper():
sys_parameters_info = get_sys_parameters_info()
r = sys_parameters_info(SPI_SETDESKWALLPAPER, 0, WALLPAPER_PATH, 3)
# When the SPI_SETDESKWALLPAPER flag is used,
# SystemParametersInfo returns TRUE
# unless there is an error (like when the specified file doesn't exist).
if not r:
print(ctypes.WinError())
change_wallpaper()
【问题讨论】:
-
你能展示你的代码吗?
-
我尝试了10个例子,我应该把它们都放出来吗?真的吗?
-
好吧,你没有提供太多信息来获得帮助。你能选择一个你认为应该有用的吗?
-
@joelgoldstick 我放了一些请检查
标签: python windows-7 background-image python-3.4