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

得意时要看淡,失意时要看开。不论得意失意,切莫大意;不论成功失败,切莫止步。志得意满时,需要的是淡然,给自己留一条退路;失意落魄时,需要的是泰然,给自己觅一条出路基于python tkinter 实现的类似于everthing的文件检索工具,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

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()

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/156956.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!