[英]Why does my desktop screen go black?
我正在嘗試將圖像制作為我的桌面圖像。
我的圖像路徑:
#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)
您的文件夾變量中有一個“\\”到多個
這篇文章: SystemParametersInfo 將壁紙設置為完全黑色(使用 SPI_SETDESKWALLPAPER)我認為解釋了這個問題。 似乎 Win32Api 是為 C 編寫的,因此需要特定格式的字符串 - 以空字符結尾的字符數組。
不完全確定如何在 Python 中傳遞這樣的數據,但希望這會為您指明正確的方向
不是它變黑了,而是你的背景變純了。 轉到您的背景設置,將背景設置為黑色以外的純色。 之后,將背景更改為圖片。 現在,運行您的代碼。 您會看到問題在於它變為純色,而不是黑色圖像。
下一個解決方案也可以提供幫助:
import os
import ctypes
folder = r"C:\folder"
file_name = r"back.jpg"
full_path = os.path.join(folder, file_name)
wallpaper = bytes(full_path, 'utf-8')
ctypes.windll.user32.SystemParametersInfoA(20, 0, wallpaper, 3)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.