옵션 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | import os import tkinter as tk import tkinter.filedialog as fd import tkinter.ttk as tp class Myapp: def __init__(self): self.opened_files = [] self.window = tk.Tk() self.window.title = "renamer" #Open 버튼을 눌러서 이름을 바꿀 파일 불러오기 self.openbutton = tk.Button(self.window,text = "Open", command = self.open_buttonclick) self.openbutton.pack() - #불러온 파일/바뀔 이름 표시 self.fileview = tp.Treeview(self.window, columns=['#1' ,'#2'], displaycolumns = ['#1','#2']) self.fileview.pack() self.fileview.column('#0',width = 40) self.fileview.heading('#0', text='Order') self.fileview.column('#1', width = 440) self.fileview.heading('#1', text = "Original Name") self.fileview.column('#2', width = 440) self.fileview.heading('#2', text= "renamed") self.filetrees = rename_preview_list(self.opened_files,'[SHANA]','') for i in self.filetrees: self.fileview.insert('','end',test = i , values = self.filetrees[i], iid = str(i)+'번') print(self.opened_files) self.window.mainloop() #파일 불러오기 def open_buttonclick(self): filenames = fd.askopenfilenames() for i in filenames: self.opened_files.append(i) #바꿀 이름을 미리 보여주기 def rename_preview_list(filelist,start,dst): filetrees = [] for i in filelist: str_name = str(i) dst_name = str(str_name.replace(start,dst)) file_keys = [str_name, dst_name] filetrees.append(tuple(file_keys)) return filetrees if __name__ == "__main__": Myapp() | cs |