forked from formazione/utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search_png_gui.py
40 lines (32 loc) · 950 Bytes
/
search_png_gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import tkinter as tk
import os
def searchfiles(extension='.txt', folder='H:\\'):
"insert all files in the listbox"
container = []
for r, d, f in os.walk(folder):
for file in f:
if file.endswith(extension):
container.append(os.path.join(r, file))
for file in container:
lb.insert(0, file)
def open_file():
os.startfile(lb.get(lb.curselection()[0]))
def clear():
lb.delete(0, tk.END)
root = tk.Tk()
root.geometry("400x400")
# ENTRY FOR THE FOLDER TO START THE SEARCH FROM
lab_en = tk.Label(root, text="Start folder")
lab_en.pack()
en = tk.Entry(root)
en.insert(0, "H:\\")
en.pack()
# BUTTON TO START SEARCH
bt = tk.Button(root, text="Search", command=lambda:searchfiles('.png', en.get()))
bt.pack()
bt2 = tk.Button(root, text="Clear", command=clear)
bt2.pack()
lb = tk.Listbox(root)
lb.pack(fill="both", expand=1)
lb.bind("<Double-Button>", lambda x: open_file())
root.mainloop()