[英]how to print current wallpaper path in windows 10 using python?
python 程序打印當前壁紙路徑為 output
我已經嘗試過這段代碼,但它不起作用
pip install py-wallpaper
from wallpaper import set_wallpaper, get_wallpaper
print(get_wallpaper())
set_wallpaper("location/to/image.jpg")
這顯示了 win-wallpaper 未被識別為內部或外部命令的錯誤
如何使用 python 在 windows 中打印當前壁紙路徑的路徑?
圖書館有一個bug
。 要克服這些步驟。
1.打開wallpaper
庫目錄,創建文件名win-wallpaper.py
。
2.將以下代碼添加到新創建的模塊中。
import ctypes,win32con
def getWallpaper():
ubuf = ctypes.create_unicode_buffer(512)
ctypes.windll.user32.SystemParametersInfoW(win32con.SPI_GETDESKWALLPAPER,len(ubuf),ubuf,0)
return ubuf.value
print(getWallpaper())
3.然后使用pyinstaller
將py
轉為exe
文件。
注意:不要將cmd
用於compile purpose
。
pyinstaller --onefile -w 'win-wallpaper.py'
4.從dist
文件夾中取出win-wallpaper.exe
文件到主目錄。 現在,對 go 很好。
但是你不應該在這里做的一件事,這個庫仍然不包含set_wallpaper(path)
function 的正確實現。 這包含很多錯誤,所以請使用最后的代碼。
import ctypes,win32con
def getWallpaper():
ubuf = ctypes.create_unicode_buffer(512)
ctypes.windll.user32.SystemParametersInfoW(win32con.SPI_GETDESKWALLPAPER,len(ubuf),ubuf,0)
return ubuf.value
def setWallpaper(path):
changed = win32con.SPIF_UPDATEINIFILE | win32con.SPIF_SENDCHANGE
ctypes.windll.user32.SystemParametersInfoW(win32con.SPI_SETDESKWALLPAPER,0,path,changed)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.