搜索D分区中所有含有关键词的文件,使用GUI界面,使用多线程,直接写完整的python代码
时间: 2023-02-06 07:12:30 浏览: 55
在这里我向您提供了一个示例代码,希望能帮到您。这段代码使用了 GUI 界面和多线程,在 D 分区中搜索所有含有关键词的文件。
请注意,这只是一个示例代码,可能并不能直接使用。实际使用时可能需要根据实际情况进行修改和调整。
```python
import os
import threading
from tkinter import *
# 定义搜索函数
def search(keyword, path):
results = []
for root, dirs, files in os.walk(path):
for file in files:
if keyword in file:
results.append(os.path.join(root, file))
return results
# 定义 GUI 界面
window = Tk()
window.title("Search Files")
# 输入框
input_frame = Frame(window)
input_frame.pack()
input_label = Label(input_frame, text="Keyword:")
input_label.pack(side=LEFT)
keyword_input = Entry(input_frame)
keyword_input.pack(side=LEFT)
# 按钮
button_frame = Frame(window)
button_frame.pack()
search_button = Button(button_frame, text="Search", command=lambda: start_search())
search_button.pack(side=LEFT)
# 结果列表
result_frame = Frame(window)
result_frame.pack()
result_list = Listbox(result_frame)
result_list.pack()
# 定义多线程函数
def start_search():
keyword = keyword_input.get()
thread = threading.Thread(target=lambda: search_in_thread(keyword))
thread.start()
def search_in_thread(keyword):
results = search(keyword, "D:\\")
for result in results:
result_list.insert(END, result)
# 启动 GUI
window.mainloop()
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)