吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 11610|回复: 170
收起左侧

[原创工具] 懒人壁纸工具,完全不占内存。会功成身退的壁纸工具

    [复制链接]
sparta 发表于 2023-7-8 15:53
代码简单,只是实现自己的想法而已。不知道有冇有和我一样想法的人。
做这个东西的理由:1、搜索壁纸复杂
                                 2、bing的壁纸还不错
                                 3、我懒得很,但我喜欢新鲜感
                                 4、其他的壁纸程序占我内存,我想要不占内存的
所以就想到了这个。就是开机启动,获取最新bing首页壁纸,然后下载,再然后设置桌面壁纸,最后功成身退,程序自己退出。
运行时候的样子,只是命令行提示

运行弹出

运行弹出

设置成功后,就是与bing首页的壁纸一样
2.jpg
[Python] 纯文本查看 复制代码
import os
import requests
import ctypes
import json
import configparser
import shutil
from datetime import date

def download_image(url, save_path):
    try:
        response = requests.get(url)
        response.raise_for_status()

        with open(save_path, 'wb') as file:
            file.write(response.content)

        print("图片下载成功!")
    except requests.HTTPError as e:
        print(f"图片下载失败:{e}")

def set_wallpaper(image_path):
    # 设置桌面背景
    SPI_SETDESKWALLPAPER = 0x0014
    ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, image_path, 3)
    print("桌面背景设置成功!")

# 读取配置文件
config = configparser.ConfigParser()
config.read('set.ini')
path = config.get('Settings', 'path')
boot = config.get('Settings', 'boot')

# 解析链接获取图片地址
url = "https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN"
response = requests.get(url)
data = response.json()
image_url = "https://cn.bing.com" + data['images'][0]['url']

# 图片保存目录
save_dir = path
# 获取今天的日期,并构建图片保存文件名
today = date.today()
save_file_name = today.strftime("%Y%m%d") + ".jpg"
# 图片保存路径和文件名
save_file_path = os.path.join(save_dir, save_file_name)

# 检查保存目录是否存在,如果不存在则新建目录
if not os.path.exists(save_dir):
    os.makedirs(save_dir)

# 下载图片
download_image(image_url, save_file_path)

# 设置桌面背景
set_wallpaper(save_file_path)

# 判断是否添加到计算机启动项
current_path = os.getcwd()
shortcut_path = os.path.join(os.environ["APPDATA"], "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "WallpaperChanger.lnk")

if boot.lower() == "yes":  # 添加到计算机启动项
    shutil.copyfile(os.path.join(current_path, "WallpaperChanger.lnk"), shortcut_path)
    print("已添加到计算机启动项")
elif boot.lower() == "no":  # 从计算机启动项移除
    if os.path.exists(shortcut_path):
        os.remove(shortcut_path)
        print("已从计算机启动项移除")
else:
    print("boot值非法,无法处理")

# 关闭程序
exit()


全部代码如上,我也打包了一份exe的


【使用说明】
再程序根目录需要有一份set.ini文件
里面的内容是
[Settings]
path = D:\Pictures
boot = no
如下图
3.png
path为图片存储目录。不存在则会创建。图片存储的名称以日期为名称:如:20230708.jpg
boot是是否开机启动,选项是no和yes 如果想要开机启动,那么改成yes后,运行一次程序,那么就会把快捷方式添加到启动项里面。如果是no,运行则会删除启动项。详情可以看代码。
蓝奏地址如下:
https://wwem.lanzoum.com/ijGtC11nz0cd
密码:hfu9

免费评分

参与人数 41吾爱币 +38 热心值 +38 收起 理由
Azx666666 + 1 + 1 用心讨论,共获提升!
ptjmzcr + 1 谢谢@Thanks!
ndtinfo + 1 谢谢@Thanks!
cyrixliu + 1 + 1 精简实用,不错!
laryCss + 1 + 1 棒极了,正需要这个
96371 + 1 + 1 谢谢@Thanks!
nhhuangzhe + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
ZQ22653 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
c8669677 + 1 + 1 谢谢@Thanks!
QAQ11 + 1 谢谢@Thanks!
usogmai + 1 + 1 我很赞同!
depp73 + 1 + 1 我很赞同!
DaiTian + 1 + 1 谢谢 @Thanks!
asylm + 1 + 1 热心回复!
haheyi0203 + 1 我很赞同!
ht1344 + 1 热心回复!
iloveyoulove + 1 + 1 谢谢@Thanks!
3536825424 + 1 + 1 我很赞同!
038 + 1 谢谢@Thanks!
Subaby + 1 谢谢@Thanks!
william0712 + 1 + 1 我很赞同!
MIN1997 + 1 热心回复!
roger8294 + 1 + 1 谢谢@Thanks!
OzzuNyn + 1 感谢您的宝贵建议,我们会努力争取做得更好!
wwvvy + 1 + 1 谢谢@Thanks!
yezicmj + 1 + 1 我很赞同!
yuanshuzhen + 1 + 1 我很赞同!
shenguoping + 1 + 1 热心回复!
15235109295 + 1 + 1 谢谢@Thanks!
ltylsy + 1 + 1 谢谢@Thanks!
candleliu + 1 + 1 谢谢@Thanks!
qingne0130 + 1 + 1 谢谢@Thanks!
你比我先挂 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
supperbot + 1 + 1 鼓励转贴优秀软件安全工具和文档!
confiant + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
hcm3292 + 1 + 1 谢谢@Thanks!
abcbbb007 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
jnXog + 1 谢谢@Thanks!
taoyie + 1 + 1 谢谢@Thanks!
浓茶 + 1 + 1 谢谢@Thanks!
风之暇想 + 7 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| sparta 发表于 2023-7-11 11:59
asencwx 发表于 2023-7-10 10:54
设置的壁纸是居中的形式,建议改为拉伸模式,谢谢

可以的。我重新打包了一份
https://wwem.lanzoum.com/ieKj311xvh6f
密码:7dmx
源码也在里面
wooj520 发表于 2023-7-13 14:03
本帖最后由 wooj520 于 2023-7-13 14:10 编辑

WIN7 64位,双击运行不可用

D:\Program Files (x86)\WallpaperChanger>WallpaperChanger.exe
Error loading Python DLL 'C:\Users\ADMINI~1\AppData\Local\Temp\_MEI79682\python3
11.dll'.
No error messages generated.
FormatMessageW: 参数错误。
LoadLibrary: PyInstaller: FormatMessageW failed.
浓茶 发表于 2023-7-9 09:03
zhuangbo 发表于 2023-7-9 09:21
很不错的东东
fxd680126 发表于 2023-7-9 09:58
感谢分享!天天有新壁纸看了。
cyrixliu 发表于 2023-7-9 10:32
bing的壁纸是还不错。 这个简单实用。
0永远快乐0 发表于 2023-7-9 10:57
需要图片,找点好看的
IMMI 发表于 2023-7-9 14:56
够简洁,感谢分享
吾然 发表于 2023-7-9 16:11
试试,谢谢,真强
redfieldw 发表于 2023-7-9 17:36
好吧这样也可以
Enola 发表于 2023-7-9 19:01
有点意思的软件
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 提醒:禁止复制他人回复等『恶意灌水』行为,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-29 11:50

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表