python - 为什么我的桌面屏幕变黑?

标签 python image python-2.7 ctypes desktop

我正在尝试将图像设为我的桌面图像。
我的图片路径:

#Image Path
import random,os
folder= r"C:\\Users\rkp10\AppData\Local\Google\Chrome\User Data\Default\Extensions\laookkfknpbbblfpciffpaejjkokdgca\0.91.6_0\backgrounds"
a=random.choice(os.listdir(folder))
print(a)

打开图像:

#Opening the Image
from PIL import Image
file = folder+'\\'+a
Image.open(file).show()

将图像设为我的桌面图像:

#Making the image as desktop image
import ctypes
image_path = file
SPI_SETDESKWALLPAPER = 20 
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, image_path, 3)

现在的问题是找到了图像路径,并且它还打开了一个图像。但是它没有将打开的图像设置为桌面图像,而是使我的桌面图像变黑。

最佳答案

这样就可以了:

import random,os
import ctypes 

folder= r"C:\Users\rkp10\AppData\Local\Google\Chrome\User Data\Default\Extensions\laookkfknpbbblfpciffpaejjkokdgca\0.91.6_0\backgrounds"
a=random.choice(os.listdir(folder)) 
print(a) file = folder+ '\\' +a
SPI_SETDESKWALLPAPER = 20 
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER , 0, file, 3)

您的文件夹变量中有一个“\”和多个“\”

关于python - 为什么我的桌面屏幕变黑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41017710/

相关文章:

javascript - 如何重写 jQuery 验证两次?

java - JPanel - 用新的较小图像替换当前显示的图像时出现问题

java - Py4JJavaError : An error occurred while calling z:org. apache.spark.api.python.PythonRDD.collectAndServe。 : java. lang.IllegalArgumentException

python-2.7 - 我可以给 theano 中的给定提供一个元组或列表吗

python - Flask 的子域?

python - 如何使用2个循环,如果为假,则无限期地重复该程序

python - 如何使用一个空格字符串清理 CSV 输入?

Python:提取字符串内标签之间的所有子字符串

java - 如何匹配BufferedImage和Mat的颜色模型?

python - 意外的 HTML 输出