Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么通过python更改桌面会导致红色墙纸?_Python_Python 3.x_Windows 10_Wallpaper - Fatal编程技术网

为什么通过python更改桌面会导致红色墙纸?

为什么通过python更改桌面会导致红色墙纸?,python,python-3.x,windows-10,wallpaper,Python,Python 3.x,Windows 10,Wallpaper,我创建了一个简单的脚本,它可以在/r/wallpaps上获得最热门的帖子,并将其下载到一个目录中,然后将其设置为我的Windows10壁纸 但是,每次我运行脚本时,我的壁纸都会变红。如果我用鼠标右键点击我下载的图片,并将其设置为我的墙纸,效果会很好 import praw import urllib.request import os import ctypes def main(): change_wallpaper(get_image()) def change_wallpape

我创建了一个简单的脚本,它可以在/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建议使用
systemparameters sinfow
而不是
systemparameters sinfoa
,现在就可以了

这回答了你的问题吗?→ 使用
系统参数infow
。它确实有效!非常感谢你!