2016-12-07 41 views
1

我正在嘗試製作一張圖像作爲我的桌面圖像。
我的圖片路徑:爲什麼我的桌面屏幕變黑?

#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) 

現在的事情是圖像路徑被發現,它也會打開一個圖像。但不是將打開的圖像設置爲桌面圖像,而是將我的桌面圖像設爲黑色。

+0

很好的瞭解,你找到了答案:) – ABcDexter

回答

1

這港島線做的伎倆:

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) 

你有一個「\」很多文件夾變量

+0

這個工作,但什麼是我的錯誤? –

+0

你的文件夾變量中有許多「\」。 –

+0

Dint讓你,對不起。更好地解釋它? –