本文共 2080 字,大约阅读时间需要 6 分钟。
# -*- coding:utf-8 -*-#author: #time: 2020/8/24import tkinter as tkfrom tkinter import filedialogfrom tkinter import ttkimport osimport cv2 as cvfrom PIL import Image#Iterate over the foldersdef iter_files(rootDir, extend_name): file_list = [] #Iterate over the roots for root,dirs,files in os.walk(rootDir): for file in files: root = os.path.normpath(root) #格式化路径 斜杠问题 file_name = os.path.join(root,file) # 连接路径 flag = file_name.endswith(extend_name) if flag: file_list.append(file_name) return file_listdef select_floder(): path = filedialog.askdirectory() var.set(path)def save_floder(): path1 = filedialog.askdirectory() var1.set(path1)window = tk.Tk()window.title('my')window.geometry('600x400')var = tk.StringVar()var1 = tk.StringVar()# create path entrye_path = tk.Entry(window, textvariable = var, width = 50)e_path.place(x = 50, y = 10)e_save_path = tk.Entry(window, textvariable = var1, width = 50)e_save_path.place(x = 50, y = 50)path_label = tk.Label(window, text = 'path:',bg = 'blue',width = 5)path_label.place(x = 10, y = 10)save_path_label = tk.Label(window, text = 'spath:',bg = 'red',width = 5)save_path_label.place(x = 10, y = 50)#create a comboboxval = tk.StringVar()cmb = ttk.Combobox(window, textvariable = val, state = 'readonly' )cmb['values'] = ('png','jpg','bmp','svg')cmb.current(0)cmb.place(x = 400, y = 10)#combobox is vacant, oddnessb_select = tk.Button(window, text = 'select folder', command = select_floder,width = 20)b_select.place(x = 300, y = 10)b_save = tk.Button(window, text = 'save folder', command = save_floder,width = 20)b_save.place(x = 300, y = 50)t = tk.Text(window, height = 5)t.place(x = 10, y = 150)def process(): var2 = e_path.get() ex_name = cmb.get() val.set(ex_name) file_list = iter_files(var2, ex_name) for name in file_list: t.insert('end',name) t.insert(tk.INSERT, '\n') #增加换行b_process = tk.Button(window, text = 'process', command = process, width = 20)b_process.place(x = 50, y = 100)window.mainloop()
转载地址:http://cxwni.baihongyu.com/