1

I tried to make a PC app to change backgrounds on your desktop, but I ran into an issue and it doesn't work. I used python tkinter library. Help is much appreciated!

def addImage():
    pic = filedialog.askopenfile(initialdir="\n", title="Izberi sliko", 
        filetypes=(("JPEG", "*.jpeg"), ("PNG","*.png"), ("all files", "*.*")))
    SPI_SETDESKWALLPAPER = 20 
    ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, pic.name, 0)


selectImage = tk.Button(root, text="Local image", padx=10, pady=5, fg="white", bg="#f6c1ff", command=addImage)
selectImage.pack()
Jackzy
  • 11
  • 2
  • 1
    Don't think it's related to your problem but instead of `filedialog.askopenfile`, you might want to use `filedialog.askopenfilename`. It returns a string of the filename instead of a file object. – TheLizzard Jul 27 '21 at 13:58
  • What doesn't work? Most likely a *dup* of https://stackoverflow.com/questions/1977694/how-can-i-change-my-desktop-background-with-python. – CristiFati Jul 27 '21 at 18:14
  • Try using `SystemParametersInfoW(...)` instead. It works in my Windows 10 running Python 3.9.6. – acw1668 Jul 27 '21 at 19:00
  • The last parameter to SystemParametersInfo is wrong. See duplicate. – Mark Tolonen Jul 27 '21 at 22:53

0 Answers0