# Rename a folder of images using Tkinter in Python 
 # Python 3 code to rename multiple image
# files in a directory or folder 
  
  
import os  
from tkinter import messagebox
import cv2
from tkinter import filedialog
from tkinter import * 
  
  
height1 = 0
width1 = 0
  
# Function to select folder to rename images
def get_folder_path():
      
    root = Tk()
    root.withdraw()
    folder_selected = filedialog.askdirectory()
      
    return folder_selected
  
  
# Function to rename multiple files
def submit():
      
    source = src_dir.get()
    src_dir.set("")
    global width1
    global height1
      
    input_folder = get_folder_path()
    i = 0
      
    for img_file in os.listdir(input_folder):
  
        file_name = os.path.splitext(img_file)[0]
        extension = os.path.splitext(img_file)[1]
  
        if extension == '.jpg':
            src = os.path.join(input_folder, img_file)
            img = cv2.imread(src)
            h, w, c = img.shape
            dst = source + '-' + str(i) + '-' + str(w) + "x" + str(h) + ".jpg"
            dst = os.path.join(input_folder, dst)
  
            # rename() function will rename all the files
            os.rename(src, dst)
            i += 1
              
    messagebox.showinfo("Done", "All files renamed successfully !!")
  
  
  
# Driver Code
if __name__ == '__main__':
    top = Tk()
    top.geometry("450x300")
    top.title("Image Files Renamer")
    top.configure(background ="Dark grey")
  
    # For Input Label
    input_path = Label(top, 
                       text ="Enter Name to Rename files:",
                       bg ="Dark grey").place(x = 40, y = 60)
      
    # For Input Textbox
    src_dir = StringVar()
    input_path_entry_area = Entry(top,
                                  textvariable = src_dir,
                                  width = 50).place(x = 40, y = 100)
  
     # For submit button
    submit_button = Button(top, 
                           text ="Submit",
                           command = submit).place(x = 200, y = 150)
  
    top.mainloop()