栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

基于python tkinter 实现的类似于everthing的文件检索工具

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

基于python tkinter 实现的类似于everthing的文件检索工具

import os
import tkinter as tk
from tkinter import messagebox,filedialog


def search():
    key=enter1.get()
    type1=enter2.get()
    # print(key,type1)
    if not key:
        messagebox.showinfo(title='ERROR !!!',message='请输入关键字')
    if not type1:
        messagebox.showinfo(title='ERROR !!!',message='请输入关键字')
        return
    # 获取文件管理器窗口
    fn=filedialog.askdirectory()
    print(fn)
    # 遍历文件目录
    fn_list=os.walk(fn)
    for root_path,dirs,files in fn_list:
        # print(root_path,dirs,files)
        for file in files:
            if file.endswith(type1):
                # print(root_path+'\'+file)
                result=root_path+'\'+file
                listbox.insert(tk.END,result)
    print('本次搜索完成')



root=tk.Tk()

root.title('搜索工具')
root.geometry('600x300')

search_frame = tk.frame()
search_frame.pack()

tk.Label(search_frame,text='关键字 :').pack(side=tk.LEFT,ipady=10,padx=5)
enter1=tk.Entry(search_frame)
enter1.pack(side=tk.LEFT,padx=5)

tk.Label(search_frame,text='文件类型 :').pack(side=tk.LEFT,ipadx=10,padx=5)
enter2=tk.Entry(search_frame)
enter2.pack(side=tk.LEFT,padx=5)

button=tk.Button(search_frame,text='搜 索')
button.pack(side=tk.LEFT,padx=30,ipadx=5)
button.config(command=search)





listbox=tk.Listbox(root,width=80)
listbox.pack(fill=tk.BOTH,expand=True)



root.mainloop()
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/444383.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号