0

I created a simple script that gets the hottest post on /r/wallpapers, downloads it to a directory, and is supposed to set it as my Windows 10 wallpaper.

However, every time I run the script my wallpaper turns red. If I were to right click on my downloaded image and set it as my wallpaper, it works fine.

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
  • 19,194
  • 5
  • 54
  • 65
  • Does this answer your question? [Creating a background changer in python with ctypes, not working](https://stackoverflow.com/questions/21715895/creating-a-background-changer-in-python-with-ctypes-not-working) → use `SystemParametersInfoW`. – mkrieger1 Jan 16 '20 at 16:56
  • It does work! Thank you so much! – Evan Nguyen Jan 16 '20 at 17:11

1 Answers1

0

user mkrieger1 suggested using SystemParametersInfoW instead of SystemParametersInfoA and it works now!

ZF007
  • 3,708
  • 8
  • 29
  • 48