我试着SO和谷歌的每个例子,但他们没有工作。我不知道为什么,剧本完成没有任何错误。但背景图像不会改变。我把这个图像的绝对路径,我试过jpg,png
格式,基本上我尝试了一切,但所有的例子完成没有任何错误,但背景图像并没有改变。有没有一个工作的例子呢? Windows的7的Python 3.4的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个例子,我应该把它们全部放在一起吗?真? – GLHF
好吧,你没有提供太多的信息来获得帮助。你能选择一个你认为应该工作的人吗? –