Python realizes batch naming photos

The specific code of python batch naming photos for your reference, the specific content is as follows

Not much nonsense, the renderings

All codes

from tkinter import*import os

# Add folder path
def rename():
 path =entry.get()
 filelist = os.listdir(path) #Get file path
 total_num =len(filelist) #Get file length (number)
 i =1 #Indicates that the naming of the file starts from 1
 for item in filelist:if item.endswith('.jpg'): #The format of the initial picture is jpg format
 src = os.path.join(os.path.abspath(path), item)
 dst = os.path.join(os.path.abspath(path),''+str(i)+'.jpg')#Naming rules after processing
   
 try:
 os.rename(src, dst)
 # print('converting %s to %s ...'%(src, dst))
 text.insert(END,'First%s Zhang was named successfully!...'%i)
 i = i +1
 except:continue
 text.insert(END,'All naming is complete!...') 

root =Tk()
root.title("Photo Batch Namer")
root.geometry("450x300")
root.minsize(450,300)
root.maxsize(450,300)
label =Label(root, text="Folder path:", font=('Microsoft Yahei',15))
label.grid(row=0,column=0)
entry =Entry(root, font=('Microsoft Yahei',15))
entry.grid(row=0, column=1)
text =Listbox(root, font=("Microsoft Yahei",15), width=37, height=8)
text.grid(row=1, columnspan=2)
button =Button(root, text="Start", font=("Microsoft Yahei",13),command=rename)
button.grid(row=2, column=0,sticky=W)
button1 =Button(root, text="drop out", font=("Microsoft Yahei",13),command=quit)
button1.grid(row=2, column=1, sticky=E)mainloop()

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

Python realizes batch naming photos
Python realizes batch modification of file names
Python realizes stitching pictures
Python realizes online translation
Python realizes tank battle
Python3 realizes airplane war game
Python realizes apple eating game
Python realizes the guessing game
Python realizes 3D map visualization
Python realizes face sign-in system
python batch run py files
Python realizes business card management system
Python3 realizes business card management system
Python realizes express price query system
Python realizes online microblog data visualization
Python realizes image recognition car function
Python realizes udp transmission picture function
Python realizes console output color font