自动更换壁纸

公司电脑总是自动给我更换了壁纸,

两种办法:
(1) 找一下是否定时任务

(2)用新的定时任务覆盖

我在第一种方法解决了这个问题...

参考:

https://www.cnblogs.com/maxstack/p/9323291.html

因此找了一段代码;

import win32api, win32con, win32gui

import random

import datetime

import time

import os

folder_path_day = r'C:\Users\Administrator.WIN-1J9R69V4VDR\Desktop\bg\day\\'

folder_path_ngt = r'C:\Users\Administrator.WIN-1J9R69V4VDR\Desktop\bg\night\\'

# https://blog.csdn.net/felixzh123/article/details/76085132

def set_wallpaper(img_path):

    # 打开指定注册表路径

    reg_key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, win32con.KEY_SET_VALUE)

    # 最后的参数:2拉伸,0居中,6适应,10填充,0平铺

    win32api.RegSetValueEx(reg_key, "WallpaperStyle", 0, win32con.REG_SZ, "6")

    # 最后的参数:1表示平铺,拉伸居中等都是0

    win32api.RegSetValueEx(reg_key, "TileWallpaper", 0, win32con.REG_SZ, "0")

    # 刷新桌面

    win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, img_path, win32con.SPIF_SENDWININICHANGE)

def count_pic_number(input_path):

    count=0

    for (root, dirs, files) in os.walk(input_path):

        for filename in files:

            count+=1

    print(count)

    return count

   

if __name__ == '__main__':

    # get current hour

    current_time = time.localtime(time.time())

    current_hour = current_time[3]

    # get image according to day or night

    if current_hour > 6 and current_hour < 18:

        print ("day")

        folder_path = folder_path_day

        pic_count_day = count_pic_number(folder_path)

        pic_number = random.randint(1,pic_count_day)

    else:

        print("night")

        folder_path = folder_path_ngt

        pic_count_ngt = count_pic_number(folder_path)

        pic_number = random.randint(1,pic_count_ngt)

    # get image absolute path

    pic_format = '.jpg'

    pic_path = folder_path + str(pic_number) + pic_format

    # change the wallpaper

    set_wallpaper(pic_path)


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值