博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
每天学一点python——GUI遍历文件夹
阅读量:4074 次
发布时间:2019-05-25

本文共 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/

你可能感兴趣的文章
使用 Apache MINA 2 开发网络应用
查看>>
MANIFEST.MF文件的格式
查看>>
NIO入门-了解Buffer
查看>>
database如何管理超过4GB的文件
查看>>
[转载]java.util.concurrent.ConcurrentHashMap 如何在不损失线程安全的同时提供更高的并发性...
查看>>
sun game server (sgs)初探
查看>>
類別 ConcurrentHashMap<K,V>的更新,删除
查看>>
如何使用Flex 4新的CSS语法,兼容halo组件
查看>>
flex addChild 的一个小细节
查看>>
Future模式,探讨mina中的Iofuture
查看>>
Java动态数组
查看>>
人生时间表. 如果您有了时间
查看>>
Adobe Flash gets its full launch on Android
查看>>
java.nio.BufferOverflowException
查看>>
对于大型公司项目平台选择j2ee的几层认识(二)
查看>>
flash player10 Vector类型
查看>>
德克萨斯扑克初级玩家必胜玩法
查看>>
Flex数据绑定陷阱:常见的误用和错误(一) - 闪吧教材.jpg
查看>>
讲讲volatile的作用
查看>>
游戏开发者的AS3数据结构 COOL!
查看>>