Windows10 桌面右鍵選單中,“個性化”--“背景”設定中可選擇“幻燈片放映”,如下圖:

用python幾行代碼就能仿制,呼叫 win32gui 模塊中的函式 SystemParametersInfo 即可實作,代碼如下:
import os,time,random
from win32gui import SystemParametersInfo
from win32con import SPI_SETDESKWALLPAPER as con1
from win32con import SPIF_SENDWININICHANGE as con2
def setWallPaper(imgPath):
SystemParametersInfo(con1, imgPath, con2)
def main():
path=r'C:\Windows\Web\Wallpaper\Theme1\\'
images=[i for i in os.listdir(path)]
while 1:
img=random.choice(images)
setWallPaper(path+img)
time.sleep(2)
# 快速測驗,間隔定為2秒
if __name__ == '__main__':
main()
另外用到了其它三個函式:
1. os.listdir() 遍歷相冊檔案夾,壁紙的檔案名讀入串列;
2. random.choice() 隨機讀取串列,模仿“無序播放”;
3. time.sleep() 播放時間間隔,在Win10中可選擇“10分鐘、30分鐘、1小時...”,
再加個高清壁紙爬蟲,在連網狀態下邊下載邊更新壁紙就更完美了,安排!

派森特給站社區
https://bbs.csdn.net/forums/PythonTogether
↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
?歡迎加入派森特給站社區!?
2021.11.04
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/349619.html
標籤:python
