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 41 42 43 44 45 46 47 48 49 50 51 52
| import os
import tkinter as tk
import tkinter.ttk as ttk
from tkinter import PhotoImage
import hashlib
class App(tk.Frame):
def __init__(self, master, path):
tk.Frame.__init__(self, master)
self._img = PhotoImage(file="videoNEG.png") # change to your file path
self._img1 = PhotoImage(file="dossierNEG.png")
style = ttk.Style(root)
style.theme_use("clam")
self.tree = ttk.Treeview(self)
ysb = tk.Scrollbar(self, orient='vertical', width=5, command=self.tree.yview)
self.tree["columns"] = ("one",)
self.tree.configure(yscroll=ysb.set, height=15)
self.tree.column('#0', width=300)
self.tree.column('#1', width=250)
self.tree.heading('#0', text=path, anchor='w')
self.tree.heading('one', text='Empreinte', anchor='w')
abspath = os.path.abspath(path)
# self.tree.tag_configure('oddrow', background="#000000")
root_node = self.tree.insert('', 'end', text=abspath, open=True)
self.process_directory(root_node, abspath)
self.tree.grid(row=0, column=0, sticky='EW')
ysb.grid(row=0, column=1, sticky='ns')
# xsb.grid(row=1, column=0, sticky='ew')
self.grid(sticky='EW')
def hash_file(self, fichier):
return hashlib.md5(open(fichier, 'rb').read()).hexdigest()
def process_directory(self, parent, path):
for p in os.listdir(path):
abspath = os.path.join(path, p)
isdir = os.path.isdir(abspath)
if p[-3:] == 'pdf':
oid = self.tree.insert(parent, 'end', text=p, open=True, image=self._img, values=(self.hash_file(abspath),))
if isdir:
oid = self.tree.insert(parent, 'end', text=p, open=True, image=self._img1)
self.process_directory(oid, abspath)
if __name__ == '__main__':
root = tk.Tk()
path_to_my_project = 'c:/python etude'
app = App(root, path=path_to_my_project)
app.mainloop() |