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,())