解决每次打开Everything都需要等待更新索引的问题
[Python] 纯文本查看 复制代码 from subprocess import Popen
from tkinter import Tk, Entry, ttk, Menu
from ctypes import WinDLL, create_unicode_buffer
def on_right_click(event):
item = tree.identify_row(event.y)
menu = Menu(root, tearoff=0)
menu.add_command(label="打开目录", command=lambda: Popen(f'explorer "{tree.item(item, "values")[1]}\\"'))
menu.post(event.x_root, event.y_root)
def search(_):
query = search_entry.get()
everything_dll.Everything_SetSearchW(query)
everything_dll.Everything_QueryW(True)
num_results = everything_dll.Everything_GetNumResults()
root.title(f'找到 {num_results} 条结果')
for item in tree.get_children():
tree.delete(item)
for i in range(min(num_results, max_results)):
buffer = create_unicode_buffer(buffer_size)
everything_dll.Everything_GetResultFullPathNameW(i, buffer, buffer_size)
path, name = buffer.value.rsplit("\\", 1)
tree.insert("", "end", values=(name, path))
everything_dll = WinDLL('Everything64.dll')
max_results = 50
buffer_size = 260
root = Tk()
root.attributes('-alpha', 0.98)
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
window_width = 1400
window_height = 650
x = (screen_width - window_width) // 2
y = (screen_height - window_height) // 2
root.geometry(f"{window_width}x{window_height}+{x}+{y}")
root.columnconfigure(0, weight=1)
root.rowconfigure(1, weight=1)
search_entry = Entry(root)
search_entry.grid(sticky="ew")
search_entry.bind("<KeyRelease>", search)
columns = ("name", "path")
tree = ttk.Treeview(root, columns=columns, show='headings')
tree.grid(sticky="nsew")
tree.heading("name", text="名称", anchor="w")
tree.heading("path", text="路径", anchor="w")
tree.bind("<Button-3>", on_right_click)
root.mainloop()
成品 ---> https://ww0.lanzoue.com/iAh2H252415a
|