先看代码。

代码

# import
import os
import sqlite3
import tkinter.filedialog as fdl
import tkinter.messagebox as msgbox
from tkinter import *
from tkinter.ttk import *
import docx
import xlrdfile = sqlite3.connect("../record.db")
cursor = file.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS record1(位置 CHAR(100),名字 CHAR(100));")
cursor.execute("CREATE TABLE IF NOT EXISTS record2(位置 CHAR(100),内容 CHAR(100));")
file.close()# function
def clear():file = sqlite3.connect("../record.db")cursor = file.cursor()for i in cursor.execute("select * from record1").fetchall():cursor.execute(f"delete from record1 where 位置='{i[0]}'")for i in cursor.execute("select * from record2").fetchall():cursor.execute(f"delete from record2 where 位置='{i[0]}'")cursor.close()file.commit()file.close()def ddl(v):d = fdl.askdirectory()if v == 1:v1.set(d)else:v2.set(d)def about():file = open("关于.txt", "r", encoding="UTF-8")ls = file.read()file.close()msgbox.showinfo("关于", ls)def Open(ns, s):try:os.startfile(list(ns[s].values())[0])except:msgbox.showerror("错误", "序号错误")def findfrominside():# where and insidecheck = msgbox.showwarning("注意", "请确认:绝对路径=" + e21.get() + ",残缺的文件内容=" + e22.get())if check == "ok":file = sqlite3.connect("../record.db")cursor = file.cursor()if e21.get() in where1 and e22.get() in where2:cursor.execute(f"INSERT INTO record2 VALUES('{e21.get()}','{e22.get()}');")cursor.close()file.commit()file.close()if os.path.isdir(e21.get()):msgbox.showinfo("提示", "开始查找...")ns = dict()count = 0for j in os.walk(e21.get()):for i in j[2]:try:if i[0] != "~" or i[0] != "." or i[0] != "$":if i.endswith(".txt") or i.endswith(".py") or i.endswith(".html") or i.endswith(".xml"):file = open(j[0] + "/" + i, "r", encoding="UTF-8")t = "".join(file.readlines())if e22.get() in t:count += 1ns[str(count) + " " + i] = j[0]elif i.endswith(".docx"):file = docx.Document(j[0] + "/" + i)ps = file.paragraphsfor p in ps:if e22.get() in p:count += 1ns[str(count) + " " + i] = j[0]elif i.endswith(".xlsx"):file = xlrd.open_workbook(j[0] + "/" + i)ss = file.sheets()for s in ss:for rn in range(s.nrows):r = s.rowvalues(rn)if e22.get() in r:count += 1ns[str(count)] = {i: j[0]}except:msgbox.showerror("错误", f"在打开文件“{i}”时发生错误!")sns = str(ns).split(",")toplevel = Toplevel(root)ls = Scrollbar(toplevel)lt = Text(toplevel, width=150, yscrollcommand=ls.set)lt.insert(INSERT, f"找到了{len(ns)}份文件,分别是")for i in range(len(sns)):lt.insert(INSERT, sns[i])lt.grid(row=0, column=0, columnspan=2)ls.grid(row=0, column=2, sticky=NS)ls.config(command=lt.yview)ll = Label(toplevel, text="序号:")ll.grid(row=1, column=0, sticky=E)le = Entry(toplevel)le.grid(row=1, column=1, sticky=W)lb = Button(toplevel, text="打开所在文件夹", command=lambda: Open(ns, le.get()))lb.grid(row=2, column=0, columnspan=2)Toplevel.mainloop()else:msgbox.showerror("错误", "绝对路径不对!")def findfromname():check = msgbox.showwarning("注意", "请确认:绝对路径=" + e11.get() + ",残缺的文件名=" + e12.get())if check == "ok":file = sqlite3.connect("../record.db")cursor = file.cursor()if not e11.get() in where1 and not e12.get() in where1:cursor.execute(f"INSERT INTO record1 VALUES('{e11.get()}','{e12.get()}');")cursor.close()file.commit()file.close()if os.path.isdir(e11.get()):msgbox.showinfo("提示", "开始查找...")fs = list(os.walk(e11.get()))ns = dict()count = 0for i in fs:for j in i[2]:if e12.get() in j:count += 1ns[str(count)] = {j: i[0]}sns = str(ns).split(",")toplevel = Toplevel(root)ls = Scrollbar(toplevel)lt = Text(toplevel, width=150, yscrollcommand=ls.set)lt.insert(INSERT, f"找到了{len(ns)}份文件,分别是:\n")for i in range(len(sns)):lt.insert(INSERT, sns[i] + "\n")lt.grid(row=0, column=0, columnspan=2)ls.grid(row=0, column=2, sticky=NS)ls.config(command=lt.yview)ll = Label(toplevel, text="序号:")ll.grid(row=1, column=0, sticky=E)le = Entry(toplevel)le.grid(row=1, column=1, sticky=W)lb = Button(toplevel, text="打开所在文件夹", command=lambda: Open(ns, le.get()))lb.grid(row=2, column=0, columnspan=2)toplevel.mainloop()else:msgbox.showerror("错误", "绝对路径不对!")# image and sql
root = Tk()
buttonphoto = PhotoImage(file="button.png")
buttonphoto = buttonphoto.subsample(4, 4)
f = sqlite3.connect("../record.db")
c = f.cursor()
where1 = []
name = []
where2 = []
inside = []
r1 = c.execute("SELECT * FROM record1;").fetchall()
for i in r1:where1.append(i[0])name.append(i[1])
r2 = c.execute("SELECT * FROM record2;").fetchall()
for i in r2:where2.append(i[0])inside.append(i[1])
f.close()# window
root.title("文件搜索大师")
menubar = Menu(root)
menubar.add_command(label="关于", command=about)
menubar.add_command(label="清空搜索记录", command=clear)
root.config(menu=menubar)
root.iconphoto(True, PhotoImage(file="icon.ico"))
n = Notebook(root, width=350, height=200)
# page1
p1 = Frame()
l11 = Label(p1, text="绝对路径:")
l11.grid(row=0, column=0)
v1 = StringVar()
e11 = Combobox(p1, textvariable=v1, values=where1, width=25)
e11.grid(row=0, column=1)
eb1 = Button(p1, image=buttonphoto, command=lambda: ddl(1))
eb1.grid(row=0, column=2)
l12 = Label(p1, text="残缺的文件名:")
l12.grid(row=1, column=0)
e12 = Combobox(p1, values=name, width=25)
e12.grid(row=1, column=1)
b1 = Button(p1, text="开始查找", command=findfromname)
b1.grid(row=2, column=0)
# page2
p2 = Frame()
l21 = Label(p2, text="绝对路径:")
l21.grid(row=0, column=0)
v2 = StringVar()
e21 = Combobox(p2, textvariable=v2, values=where2, width=25)
e21.grid(row=0, column=1)
eb2 = Button(p2, image=buttonphoto, command=lambda: ddl(2))
eb2.grid(row=0, column=2)
l22 = Label(p2, text="残缺的文件内容:")
l22.grid(row=1, column=0)
e22 = Combobox(p2, values=inside, width=25)
e22.grid(row=1, column=1)
b2 = Button(p2, text="开始查找", command=findfrominside)
b2.grid(row=2, column=0)
# note
n.add(p1, text="根据文件名查找文件")
n.add(p2, text="根据文件内容查找文件")
n.grid()
root.mainloop()

共计221行。全是肝啊!

文件列表

  • 文件搜索大师

    • button.png
    • icon.ico
    • record.db
    • 关于.txt
    • 文件搜索大师.py

后来我甚至封装成了软件。
可以自己复制来用。

下载

百度网盘链接:链接
提取码: 0212

注:已经打包成软件了哟!
古德拜~ 总是用这句话做结尾,没意思!

一大堆模块的结晶……相关推荐

  1. wxpython可视化_使用wxPython的绘图模块wxPyPlot进行数据可视化

    [Python进阶(四十)-数据可视化の使用matplotlib进行绘图前言  matplotlib是基于Python语言的开源项目,旨在为Python提供一个数据绘图包.我将在这篇文章中介绍matp ...

  2. python语言入门z-python中a z

    广告关闭 2017年12月,云+社区对外发布,从最开始的技术博客到现在拥有多个社区产品.未来,我们一起乘风破浪,创造无限可能. def collatz(n): if n % 2 == 0: n=n2 ...

  3. python自定义函数画图_利用Python绘图和可视化(长文慎入)

    Python有许多可视化工具,但是我主要讲解matplotlib(http://matplotlib.sourceforge.net).此外,还可以利用诸如d3.js(http://d3js.org/ ...

  4. 我眼中的各种编程语言

    所有的编程语言我都讨厌.曾经我想自创一门语言,但我没搞明白到底需要一门什么语言,所以也从未开始过. 许多时候,你没法选择使用哪种语言.不管我在用哪种语言,我都尝试去接受它的优点和缺点. Java 喜欢 ...

  5. Python 中的面向对象没有意义

    编译 | 弯月   责编 | 张文 出品 | CSDN(ID:CSDNnews) 许多人都在抨击面向对象,虽然我不认为他有什么问题,但我觉得至少在 Python 中没必要. 近来,许多人都在抨击面向对 ...

  6. python面向对象有什么用_Python 中的面向对象没有意义

    许多人都在抨击面向对象,虽然我不认为他有什么问题,但我觉得至少在Python 中没必要. 近来,许多人都在抨击面向对象,虽然我不认为面向对象本身有什么问题,但我觉得至少在 Python 中没这个必要. ...

  7. matplotlib一些常用知识点的整理,

    本文作为学习过程中对matplotlib一些常用知识点的整理,方便查找. 强烈推荐ipython 无论你工作在什么项目上,IPython都是值得推荐的.利用ipython --pylab,可以进入Py ...

  8. 对dedecms、php168,phpcms、VeryCMS、DiyPage五款开源整站系统的简单评点(

    随着phpcms的开源,目前国内的开源整站系统(cms),已经有了三款功能比较强大的软件:dedecms.php168,phpcms,另外还有一个半吊子成品VeryCMS和一个起步中的DiyPage, ...

  9. python中用于绘制各种图形的区域称作_Python--matplotlib绘图可视化知识点整理(示例代码)...

    强烈推荐ipython 原文:http://michaelxiang.me/2016/05/14/python-matplotlib-basic/ 无论你工作在什么项目上,IPython都是值得推荐的 ...

最新文章

  1. Java测试工具使用(1)--Junit
  2. 【Storm】storm安装、配置、使用以及Storm单词计数程序的实例分析
  3. WEBSERVICE之JDK开发webservice
  4. dnf剑魂buff等级上限_剑魂完美换装BUFF!远古遗愿的用处很大么?
  5. linux安装java_Linux安装JDK完整步骤
  6. 0705 - 说说 NSPopover 的一个坑
  7. ELK7.8.1的Docker搭建过程
  8. Visual Paradigm中文乱码
  9. 安卓开发学习笔记(六):如何实现指定图片定时开屏功能?
  10. logstash之codec插件
  11. Linkedin第三方登录集成(android)
  12. 使用ARCGIS对shp数据添加投影坐标系
  13. DB2 SQLCODE常见错误代码
  14. Android音频的录制与播放
  15. 小心了,京东订单详情会变?下单记得录屏
  16. layui教程(一) form 表单的提交问题
  17. 打开个税App:竟要补税两万多...
  18. Tableau实用小技巧之——双轴图表设置同步轴
  19. c语言欢迎界面程序设计,C语言程序设计报告
  20. Error:Internal error: (java.lang.IllegalArgumentException) Argument for

热门文章

  1. 每日一个小技巧:今天告诉你拍照识别文字的软件有哪些
  2. 5款高逼格实用手机APP推荐,千万不能错过!
  3. 程序人生--hello‘s P2P(From Program to Process)
  4. 视频号|常见违规限流情况及解除方法
  5. Global项目|浅析销售BOM实施方案及注意事项
  6. mysql查询近一年数据
  7. angularjs grunt uglify 报错
  8. iOS 最完整小说阅读器Demo
  9. (一)验证微信公众平台
  10. java 微信 推送_JAVA 微信消息模板推送