python设置win10壁纸

import os,random,re
import win32gui,win32con #pypiwin32
from PIL import Image

ds=[
{"paths":["e:/图片/壁纸/"],"type":1},
{"paths":["D:/output/图片/"],"type":2,"sizes":[600,680,680,600]}
];

index=[0,1,1,0,1,1,1];

wallpaper="c:/users/admin/desktop/wallpaper.jpg";
width=2560;
height=1440;

def getFiles(path):
    r=[];
    for root,dirs,files in os.walk(path):
        for v in files:
            if re.match('.+\\.(jpg|png|jpeg|bmp|gif)$',v,re.I):
                r.append(os.path.join(root,v))
    return r;

ds=ds[index[random.randint(0,len(index)-1)]];

if ds["type"]==1:
    paths=ds["paths"];
    paths=getFiles(paths[random.randint(0,len(paths)-1)]);
    random.shuffle(paths);
    wallpaper=paths[random.randint(0,len(paths)-1)];
else:
    sizes=ds["sizes"]
    imgs=[];
    for v in ds["paths"]:
        for v2 in getFiles(v):
            imgs.append(v2);
    i=0;
    while i<11:
        random.shuffle(imgs);
        i+=1;
    pic=Image.new("RGBA",(width,height),(255,255,255,255));
    w=0;
    h=0;
    index=0;
    for size in sizes:
        h=0;
        while h<height:
            img=Image.open(imgs[index%len(imgs)]);
            index+=1;
            if img.width>size:
                img=img.resize((size,int(size/(img.width/img.height))),Image.Resampling.LANCZOS);
            pic.paste(img,(int(w+(size-img.width)/2), h));
            h+=img.height;
        w+=size;
    pic.save(wallpaper,"PNG");
print(wallpaper);
win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER,wallpaper,1);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值