0

This code does that when you run it, there will be a app that will have 2 buttons. If you click one the "local files" one, the windows explorer will pop up. And now I want to know how to when you select a picture in the explorer, the programme will set it as your windows desktop background.

import tkinter as tk
from tkinter import filedialog, Text
import os

root = tk.Tk()
canvas = tk.Canvas(root, height=500, width=900)
canvas.pack()

def addImage():
    slika = filedialog.askopenfile(initialdir="\n", title="Izberi sliko", 
        filetypes=(("JPEG", "*.jpeg"), ("PNG","*.png"), ("all files", "*.*")))

selectImage = tk.Button(root, text="Local image", padx=10, pady=5, fg="white", bg="#f6c1ff", command=addImage)
selectImage.pack()

ourLibrary = selectImage = tk.Button(root, text="WPManager library", padx=10, pady=5, fg="white", bg="#f6c1ff")
selectImage.pack()

root.mainloop()```
Jackzy
  • 11
  • 2

1 Answers1

0

edit: in your case, use slika.name to access the chosen file's full path

EITHER A:

Copy the relevant image to C:\Users\wolf3\AppData\Roaming\Microsoft\Windows\Themes\CachedFiles.

You might also want to check and delete C:\Users\wolf3\AppData\Roaming\Microsoft\Windows\Themes\TranscodedWallpaper if it exists.

Finally, call os.system("rundll32.exe user32.dll, UpdatePerUserSystemParameters"), a few times (3 or so- I have found it to be more realiable than one update), and your wallpaper should have updated.

OR B:

import ctypes
SPI_SETDESKWALLPAPER = 20 
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, "image.jpg" , 0)

from How can I change my desktop background with python?

NOTE:

From personal experience and from the comments in the question above, .bmp files will definitely work with these methods, unfortunately I cannot guarantee any others will work consistently.