日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 遍历listbox_Python仿evething的文件搜索器 !

發布時間:2025/3/19 python 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 遍历listbox_Python仿evething的文件搜索器 ! 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

今天看到everything搜索速度秒殺windows自帶的文件管理器,所以特地模仿everything實現了文件搜索以及打開對應文件的功能,首先來一張搜索對比圖。

這是evething搜索效果:

Python學習交流群:1004391443,這里有資源共享,技術解答,還有小編從最基礎的Python資料到項目實戰的學習資料都有整理,希望能幫助你更了解python,學習python。

這是自己實現的效果:

主要功能就是python的os庫的文件列表功能,sqllite創建表,插入數據以及模糊搜索,然后就是tkiner實現的界面功能。全部代碼貼出來做一次記錄,花費一天時間踩坑。

# coding=utf-8import tkinter as tkimport tkinter.messagebox #這個是消息框,對話框的關鍵import tkinter.constantsimport sqlite3import osimport threadingimport traceback def update_db(): print("更新數據庫") tkinter.messagebox.showerror("錯誤提示","更新數據庫功能未完待續,可以刪除目錄下的allFiles.db文件,然后點擊搜索,即可刷新數據庫") def mouseCallBack(*args): indexs = listb.curselection() index = int(indexs[0]) print("index",index) start_directory = str(myArr[index]) print(start_directory[2:-3]) os.startfile(start_directory[2:-3]) def obtain_all_files(filepath,cursor):#遍歷filepath下所有文件,包括子目錄 try: files = os.listdir(filepath) for fi in files: fi_d = os.path.join(filepath,fi) if os.path.isdir(fi_d): obtain_all_files(fi_d,cursor) else: path = os.path.join(filepath,fi_d) update_progress.set(path) print("目錄",path) sqlAdd = "insert into filepath (file_path) values ('"+path+"')" print("sqlAdd",sqlAdd) cursor.execute(sqlAdd) except Exception as e: traceback.print_exc() print("掃描文件出異常了,點擊確定繼續掃描") tkinter.messagebox.showerror("錯誤提示","掃描文件出異常了看,點擊確定繼續掃描") def scan_file(): print("開始掃描文件") # del myArr[:] connection.execute("BEGIN TRANSACTION;") # 關鍵點 cursor = connection.cursor() obtain_all_files('G:',cursor) print("G盤掃描完成...") tkinter.messagebox.showinfo("溫馨提示","G盤掃描完成....") connection.execute("COMMIT;") #關鍵點 connection.commit() connection.close() def insert_db(): t1 = threading.Thread(target=scan_file) t1.setDaemon(True) t1.start() tkinter.messagebox.showinfo("溫馨提示","正在更新數據庫,請等待...") def search_file(): #表示創建一個數據庫,并獲得連接 print("數據庫是否存在: ",isExistDB) if(isExistDB==False): tkinter.messagebox.showwarning("警告","數據庫不存在,將更新數據庫文件!") try: mycursor = connection.cursor() file_sql = "create table filepath('file_path' text not null)" mycursor.execute(file_sql) mycursor.close() insert_db() except: tkinter.messagebox.showerror("錯誤提示","數據庫發生異常...") return else: print("開始搜索") listb.delete(0,tk.constants.END) mycursor = connection.cursor() entry_text = inputText.get() search_sql = "select * from filepath where file_path like '%"+entry_text+"%'" files = mycursor.execute(search_sql) #tkinter.messagebox.showwarning("警告","沒有找到對應的文件!") for f in files: print(f) myArr.append(f) listb.insert(tkinter.constants.END,f) print("搜索完成") mycursor.close() myArr = []isExistDB = os.path.exists("allFiles.db")connection = sqlite3.connect("allFiles.db",check_same_thread = False)root = tk.Tk() # 初始化Tk()root.title("電腦文件搜索工具(仿everything)By景兄弟V1.0") # 設置窗口標題root.geometry("800x600") # 設置窗口大小 注意:是x 不是*root.resizable(width=False, height=False) # 設置窗口是否可以變化長/寬,False不可變,True可變,默認為True#設置輸入框inputText = tk.Entry(root,show=None,foreground = 'red',font = ('Helvetica', '15', 'bold'),insertbackground = 'green',width=65)inputText.pack()#設置按鈕,以及放置的位置searchBtn = tk.Button(root, text="搜索", fg="blue",bd=2,width=10,command=search_file)#command中的方法帶括號是直接執行,不帶括號才是點擊執行searchBtn.place(x=200, y=40, anchor='nw')updateBtn = tk.Button(root, text="更新數據庫", fg="blue",bd=2,width=10,command=update_db)updateBtn.place(x=400, y=40, anchor='nw') update_progress = tk.StringVar()update_progress.set('還未開始掃描')lb = tk.Label(root,text="還未開始", fg="blue",bd=2,width=100, textvariable=update_progress)lb.place(x=20,y=90) listb = tk.Listbox(root,width=110,height=20)listb.place(x=1, y=120, anchor='nw')sb = tk.Scrollbar(root) #垂直滾動條組件sb.pack(side=tkinter.constants.RIGHT,fill=tkinter.constants.Y) #設置垂直滾動條顯示的位置listb.config(yscrollcommand=sb.set)listb.bind("<<ListboxSelect>>",mouseCallBack)root.mainloop() # 進入消息循環

今天看到everything搜索速度秒殺windows自帶的文件管理器,所以特地模仿everything實現了文件搜索以及打開對應文件的功能,首先來一張搜索對比圖。

這是evething搜索效果:

這是自己實現的效果:

主要功能就是python的os庫的文件列表功能,sqllite創建表,插入數據以及模糊搜索,然后就是tkiner實現的界面功能。全部代碼貼出來做一次記錄,花費一天時間踩坑。

# coding=utf-8import tkinter as tkimport tkinter.messagebox #這個是消息框,對話框的關鍵import tkinter.constantsimport sqlite3import osimport threadingimport traceback def update_db(): print("更新數據庫") tkinter.messagebox.showerror("錯誤提示","更新數據庫功能未完待續,可以刪除目錄下的allFiles.db文件,然后點擊搜索,即可刷新數據庫") def mouseCallBack(*args): indexs = listb.curselection() index = int(indexs[0]) print("index",index) start_directory = str(myArr[index]) print(start_directory[2:-3]) os.startfile(start_directory[2:-3]) def obtain_all_files(filepath,cursor):#遍歷filepath下所有文件,包括子目錄 try: files = os.listdir(filepath) for fi in files: fi_d = os.path.join(filepath,fi) if os.path.isdir(fi_d): obtain_all_files(fi_d,cursor) else: path = os.path.join(filepath,fi_d) update_progress.set(path) print("目錄",path) sqlAdd = "insert into filepath (file_path) values ('"+path+"')" print("sqlAdd",sqlAdd) cursor.execute(sqlAdd) except Exception as e: traceback.print_exc() print("掃描文件出異常了,點擊確定繼續掃描") tkinter.messagebox.showerror("錯誤提示","掃描文件出異常了看,點擊確定繼續掃描") def scan_file(): print("開始掃描文件") # del myArr[:] connection.execute("BEGIN TRANSACTION;") # 關鍵點 cursor = connection.cursor() obtain_all_files('G:',cursor) print("G盤掃描完成...") tkinter.messagebox.showinfo("溫馨提示","G盤掃描完成....") connection.execute("COMMIT;") #關鍵點 connection.commit() connection.close() def insert_db(): t1 = threading.Thread(target=scan_file) t1.setDaemon(True) t1.start() tkinter.messagebox.showinfo("溫馨提示","正在更新數據庫,請等待...") def search_file(): #表示創建一個數據庫,并獲得連接 print("數據庫是否存在: ",isExistDB) if(isExistDB==False): tkinter.messagebox.showwarning("警告","數據庫不存在,將更新數據庫文件!") try: mycursor = connection.cursor() file_sql = "create table filepath('file_path' text not null)" mycursor.execute(file_sql) mycursor.close() insert_db() except: tkinter.messagebox.showerror("錯誤提示","數據庫發生異常...") return else: print("開始搜索") listb.delete(0,tk.constants.END) mycursor = connection.cursor() entry_text = inputText.get() search_sql = "select * from filepath where file_path like '%"+entry_text+"%'" files = mycursor.execute(search_sql) #tkinter.messagebox.showwarning("警告","沒有找到對應的文件!") for f in files: print(f) myArr.append(f) listb.insert(tkinter.constants.END,f) print("搜索完成") mycursor.close() myArr = []isExistDB = os.path.exists("allFiles.db")connection = sqlite3.connect("allFiles.db",check_same_thread = False)root = tk.Tk() # 初始化Tk()root.title("電腦文件搜索工具(仿everything)By景兄弟V1.0") # 設置窗口標題root.geometry("800x600") # 設置窗口大小 注意:是x 不是*root.resizable(width=False, height=False) # 設置窗口是否可以變化長/寬,False不可變,True可變,默認為True#設置輸入框inputText = tk.Entry(root,show=None,foreground = 'red',font = ('Helvetica', '15', 'bold'),insertbackground = 'green',width=65)inputText.pack()#設置按鈕,以及放置的位置searchBtn = tk.Button(root, text="搜索", fg="blue",bd=2,width=10,command=search_file)#command中的方法帶括號是直接執行,不帶括號才是點擊執行searchBtn.place(x=200, y=40, anchor='nw')updateBtn = tk.Button(root, text="更新數據庫", fg="blue",bd=2,width=10,command=update_db)updateBtn.place(x=400, y=40, anchor='nw') update_progress = tk.StringVar()update_progress.set('還未開始掃描')lb = tk.Label(root,text="還未開始", fg="blue",bd=2,width=100, textvariable=update_progress)lb.place(x=20,y=90) listb = tk.Listbox(root,width=110,height=20)listb.place(x=1, y=120, anchor='nw')sb = tk.Scrollbar(root) #垂直滾動條組件sb.pack(side=tkinter.constants.RIGHT,fill=tkinter.constants.Y) #設置垂直滾動條顯示的位置listb.config(yscrollcommand=sb.set)listb.bind("<<ListboxSelect>>",mouseCallBack)root.mainloop() # 進入消息循環

總結

以上是生活随笔為你收集整理的python 遍历listbox_Python仿evething的文件搜索器 !的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲国产黄色av | 97在线观视频免费观看 | 视频二区 | 穿越异世荒淫h啪肉np文 | 精品人妻一区二区三区四区不卡 | 成人一区二区三区在线观看 | 男人操女人免费网站 | 成年免费在线观看 | 在线免费观看国产视频 | 好屌妞视频这里只有精品 | 欧美大片xxx | 午夜激情福利在线 | 色网站在线看 | 久久电影一区二区 | 亚洲欧美另类视频 | 欧美又粗又深又猛又爽啪啪九色 | 天天操天天射天天爱 | 手机看片久久 | 婷婷丁香激情五月 | www免费黄色 | 精品日本一区二区三区在线观看 | 久久99国产综合精品免费 | 亚洲天堂免费看 | 山村大伦淫第1部分阅读小说 | 久久中文字幕在线观看 | 狠狠撸在线视频 | 国产又爽又猛又粗的视频a片 | 日韩人妻精品在线 | 天堂а√在线中文在线鲁大师 | 在线视频一区二区三区 | 亚洲性av| 久久澡 | 精品免费在线观看 | 国产精品美女久久久久图片 | 蜜桃视频在线入口www | 国产免费一区二区三区网站免费 | 日韩中文字幕av电影 | 午夜一区二区三区 | 日韩三级免费观看 | 欧美无砖砖区免费 | 好男人天堂网 | 亚洲综合视频一区 | 色性网站 | 尤物视频在线观看视频 | 毛片在哪看 | 日韩a级片| 成人福利网站在线观看 | 亚洲热视频 | 欧美亚洲一区二区在线观看 | 国语对白真实视频播放 | 朝桐光在线播放 | 美女脱了裤子让男人捅 | 日韩福利在线观看 | 看黄色网址 | 色屁屁视频 | 91肉色超薄丝袜脚交一区二区 | 久久久久久国 | 国产精品久久久久无码av | 风流老熟女一区二区三区 | 日日噜夜夜噜 | 日韩久久精品视频 | 乱xxxxx普通话对白 | jizz欧美大全 | www.色呦呦 | 十大污视频 | www.欧美色 | 精国产人伦一区二区三区 | 4438亚洲 | 一区二区三区三区在线 | 亚洲第一区在线观看 | 国产成人精品一区二区在线观看 | 天天综合天天色 | 国产精品视频第一页 | 成人午夜一区二区 | www亚洲视频| 国产精品不卡在线 | 午夜精品福利影院 | 夜夜操夜夜爱 | 国产精品国产三级国产专区52 | 国产美女视频免费观看下载软件 | 天天操人人 | 九九视频免费 | 亚洲+小说+欧美+激情+另类 | 日本99视频 | 妖精视频一区二区三区 | 我的公把我弄高潮了视频 | 久久欧| 乐播av一区二区三区 | 欧美91视频 | 99久久久国产 | 黄色小视频入口 | av动漫免费看| 欧美日韩激情在线观看 | 亚洲少妇一区二区三区 | 亚洲自拍图片 | 欧美性猛交xxxx | 免费亚洲精品 | 日本特黄视频 | 成人短视频在线免费观看 |