【python小白提问】用python换个桌面背景

2020-05-08 社会 66阅读
path="D:\我的文档\My Pictures\wallpaper" #壁纸目录
newpath=os.path.join(os.getenv("appdata"),"Microsoft\Wallpaper1.bmp")
Getwnd=FindWindow("Shell_TrayWnd",None)
screen_height0=GetSystemMetrics (win32con.SM_CYSCREEN)
screen_height=screen_height0-GetClientRect(Getwnd)[3]
screen_width=GetSystemMetrics (win32con.SM_CXSCREEN)
def change_wallpaper():
filelist=os.listdir(path)
ranpic=filelist[random.randint(0,len(filelist)-1)]
filefullpath="%s\%s" % (path,ranpic)
im=Image.open(filefullpath)
if im.size[0] !=screen_width or im.size[1]!=screen_height0:return
im.save(newpath, "BMP")
windll.user32.SystemParametersInfoA(20, 0,newpath, 0)
def wallpaper_thread():
while 1:
change_wallpaper()
sleeptime=random.randint(15,30)*60
print sleeptime
time.sleep(sleeptime)
thread.start_new_thread(wallpaper_thread,())
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com