|
| 1 | +#Importing libraries. pillows for image stuff, tkinter for windows explorer |
| 2 | + |
| 3 | +import tkinter as tk |
| 4 | +from tkinter import filedialog |
| 5 | +from PIL import Image, ImageTk |
| 6 | + |
| 7 | +#function for opening windows explorer and then the original image |
| 8 | + |
| 9 | +def Original(): |
| 10 | + file_path = filedialog.askopenfilename(filetypes=[("Image files", "*.jpg *.jpeg *.png")]) |
| 11 | + if file_path: |
| 12 | + img = Image.open(file_path) |
| 13 | + img = img.resize((100, 100)) |
| 14 | + img_tk = ImageTk.PhotoImage(img) |
| 15 | + label.config(image=img_tk) |
| 16 | + label.image = img_tk |
| 17 | + |
| 18 | +#function for opening windows explorer and then the mask image |
| 19 | + |
| 20 | +def Mask(): |
| 21 | + mask_path = filedialog.askopenfilename(filetypes=[("Image files", "*.jpg *.jpeg *.png")]) |
| 22 | + if mask_path: |
| 23 | + img2 = Image.open(mask_path) |
| 24 | + img2 = img2.resize((100, 100)) |
| 25 | + img2_tk = ImageTk.PhotoImage(img2) |
| 26 | + label2.config(image=img2_tk) |
| 27 | + label2.image = img2_tk |
| 28 | + |
| 29 | + |
| 30 | +#create root window |
| 31 | +window = tk.Tk() |
| 32 | + |
| 33 | +# Set window title |
| 34 | +window.title('File Explorer') |
| 35 | + |
| 36 | +# Set window size |
| 37 | +window.geometry("500x500") |
| 38 | + |
| 39 | +#Set window background color |
| 40 | +window.config(background = "white") |
| 41 | + |
| 42 | +# Create a File Explorer label |
| 43 | +label = tk.Label(window,text = "Selecting Images") |
| 44 | + |
| 45 | +#Top text |
| 46 | +label2 = tk.Label(window,text = " ") |
| 47 | + |
| 48 | +#Original image selecting button |
| 49 | +button_og = tk.Button(window,text = "Select original image",command = Original) |
| 50 | + |
| 51 | +#Mask image selecting button |
| 52 | +button_mask = tk.Button(window,text = "Select masked image",command = Mask) |
| 53 | + |
| 54 | +#Exit button |
| 55 | +button_exit = tk.Button(window,text = "Exit",command = exit) |
| 56 | + |
| 57 | + |
| 58 | +# Grid method is chosen for placing the widgets at respective positions in a table like structure by specifying rows and columns |
| 59 | +label.grid(column = 49, row = 1) |
| 60 | + |
| 61 | +label2.grid(column=51,row=1) |
| 62 | + |
| 63 | +button_og.grid(column = 50, row = 4) |
| 64 | + |
| 65 | +button_mask.grid(column=50,row=5) |
| 66 | + |
| 67 | +button_exit.grid(column = 50,row = 6) |
| 68 | +# Let the window wait for any events |
| 69 | +window.mainloop() |
0 commit comments