|
| 1 | +# import modules |
| 2 | +from tkinter import * |
| 3 | +from tkinter import filedialog |
| 4 | +from wallpaper import set_wallpaper |
| 5 | + |
| 6 | +# user define function |
| 7 | +def change_wall(): |
| 8 | + |
| 9 | + # set your photo |
| 10 | + try: |
| 11 | + set_wallpaper(str(path.get())) |
| 12 | + check = "success" |
| 13 | + |
| 14 | + except: |
| 15 | + |
| 16 | + check = "Wallpaper not found !" |
| 17 | + result.set(check) |
| 18 | + |
| 19 | + |
| 20 | +def browseFiles(): |
| 21 | + filename = filedialog.askopenfilename(initialdir="/", |
| 22 | + title="Select a File", |
| 23 | + filetypes=(("jpeg files", "*.jpg"), ("all files", "*.*"))) |
| 24 | + path.set(filename) |
| 25 | + |
| 26 | + # Change label contents |
| 27 | + label_file_explorer.configure(text="File Opened: "+filename) |
| 28 | + return filename |
| 29 | + |
| 30 | + |
| 31 | +# object of tkinter |
| 32 | +# and background set for red |
| 33 | +master = Tk() |
| 34 | +master.configure(bg='light grey') |
| 35 | + |
| 36 | +# Variable Classes in tkinter |
| 37 | +result = StringVar() |
| 38 | +path = StringVar() |
| 39 | + |
| 40 | + |
| 41 | +label_file_explorer = Label( |
| 42 | + master, text="Select a image", width=100, fg="blue") |
| 43 | + |
| 44 | + |
| 45 | +# Creating label for each information |
| 46 | +# name using widget Label |
| 47 | +Label(master, text="Select image : ", bg="light grey").grid(row=0, sticky=W) |
| 48 | +Label(master, text="Status :", bg="light grey").grid(row=3, sticky=W) |
| 49 | + |
| 50 | + |
| 51 | +# Creating label for class variable |
| 52 | +# name using widget Entry |
| 53 | +Label(master, text="", textvariable=result, |
| 54 | + bg="light grey").grid(row=3, column=1, sticky=W) |
| 55 | + |
| 56 | +# creating a button using the widget |
| 57 | +# Button that will call the submit function |
| 58 | +b = Button(master, text="Open", command=browseFiles, bg="white") |
| 59 | +b.grid(row=0, column=2, columnspan=2, rowspan=2, padx=5, pady=5,) |
| 60 | + |
| 61 | +label_file_explorer.grid(column=1, row=1) |
| 62 | + |
| 63 | +c = Button(master, text="Apply", command=change_wall, bg="white") |
| 64 | +c.grid(row=2, column=2, columnspan=2, rowspan=2, padx=5, pady=5,) |
| 65 | + |
| 66 | +mainloop() |
0 commit comments