我正在编写一个简单的(我认为是)程序,为一周中的每一天设置不同的桌面背景。它运行时没有任何错误,但什么也没有发生。图像的路径有效。有什么想法吗?
import time;
import ctypes;
SPI_SETDESKWALLPAPER = 20
localtime = time.localtime(time.time())
wkd = localtime[6]
if wkd == 6:
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\1.jpg",0)
elif wkd == 0:
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\2.jpg",0)
elif wkd == 1:
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\3.jpg",0)
elif wkd == 2:
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\4.jpg",0)
elif wkd == 3:
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\5.jpg",0)
elif wkd == 4:
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\6.jpg",0)
elif wkd == 5:
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\7.jpg",0)发布于 2016-12-31 15:10:58
如果你使用的是Python3,你应该使用ctypes.windll.user32.SystemParametersInfoW而不是ctypes.windll.user32.SystemParametersInfoA( this answer说的是W而不是A)。Another answer对此进行了描述,因为在Python3中,str类型的形式是UTF-16,就像C中的wchar_t *一样。
更重要的是,请最小化代码,如下所示:
import time;
import ctypes;
SPI_SETDESKWALLPAPER = 20
wallpapers = r"C:\Users\Owner\Documents\Wallpaper\%d.jpg"
localtime = time.localtime(time.time())
wkd = localtime[6]
ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, wallpapers%(wkd+1), 0)不要重复你的话。
https://stackoverflow.com/questions/21715895
复制相似问题