I have a python script that should technically change my wallpaper to a downloaded .jpg file. While the code executes without any errors, my wallpaper changes to black color with no image. I am not sure whether I made a mistake, or there is a different approach that will work. Thanks for looking, Cheers!
I am running Windows Version of Python(v3.6.0a4)
import ctypes
import urllib
import os
import urllib.request
SPI_SETDESKWALLPAPER = 20
f = open('env.jpg','wb')
f.write(urllib.request.urlopen('http://i68.tinypic.com/vzhlrp.jpg').read())
path = os.getcwd() + "\env.jpg"
print("\n" + path)
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, path , 0)
I also tried changing the path to 'C:\env.jpg', it does not work also.
EDIT Also tried a more stable version of python, v3.5.1, still does not work
EDIT 2 Finally figured it out, I needed to add f.close() to close stream.
import ctypes
import urllib
import os
import urllib.request
SPI_SETDESKWALLPAPER = 20
f = open('env.jpg','wb')
f.write(urllib.request.urlopen('http://i68.tinypic.com/vzhlrp.jpg').read())
f.close() #THIS LINE MADE ALL THE DIFFERENCE
path = os.path.join(os.getcwd(), "env.jpg")
print("\n" + path)
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, path , 0)