gpt4 book ai didi

python - 使用 ctypes 在 python 中创建背景转换器,不工作

转载 作者:太空宇宙 更新时间:2023-11-04 10:39:15 24 4
gpt4 key购买 nike

我正在开发一个简单的(我认为)程序来为一周中的每一天设置不同的桌面背景。它运行没有错误,但没有任何反应。图像的路径是有效的。有什么想法吗?

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)

最佳答案

我一定已经阅读了关于这个主题的所有现有站点,并且在放弃之前,来到了这个工作代码(win7 pro 64 位,python 3.4)

import ctypes
SPI_SETDESKWALLPAPER = 0x14 #which command (20)

SPIF_UPDATEINIFILE = 0x2 #forces instant update
src = r"D:\Downloads\_wallpapers\3D-graphics_Line_025147_.jpg" #full file location
#in python 3.4 you have to add 'r' before "path\img.jpg"

print(ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, src, SPIF_UPDATEINIFILE))

它使用 SystemParametersInfoW 而不是 SystemParametersInfoA(W 而不是 A)。

希望它能帮助您和许多其他似乎有类似问题的人。

关于python - 使用 ctypes 在 python 中创建背景转换器,不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21715895/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com