我创建了一个简单的脚本,它可以在/r/wallpaps上获得最热门的帖子,并将其下载到一个目录中,然后将其设置为我的Windows10壁纸
但是,每次我运行脚本时,我的壁纸都会变红。如果我用鼠标右键点击我下载的图片,并将其设置为我的墙纸,效果会很好
import praw
import urllib.request
import os
import ctypes
def main():
change_wallpaper(get_image())
def change_wallpaper(url):
SPI_SETDESKWALLPAPER = 20
directory = os.path.dirname(os.path.realpath(__file__)) + "\\bin\\" + 'image.jpg'
urllib.request.urlretrieve(url,directory)
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, directory, 0)
def get_image():
reddit = praw.Reddit(client_id='id', client_secret='secret', user_agent='app')
get_hottest = reddit.subreddit('wallpapers').hot(limit=1)
for post in get_hottest:
url = post.url
title = post.title
author = post.author
return url
main()
用户mkrieger1建议使用
SystemParametersInfoW
而不是SystemParametersInfoA
,现在就可以了相关问题 更多 >
编程相关推荐