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
| import os
from tkinter import *
from tkinter.ttk import *
class MaFenetre(Tk):
def __init__(self,path):
Tk.__init__(self)
self.root=Tk()
self.lab=Label(self)
self.fichierSelect =StringVar()
self.tree= MonTreeview(path)
self.navigation=Combobox(self.root,textvariable=self.tree,
values=self.fichierSelect, state='readonly')
self.navigation.bind('<<ComboboxSelected>>', self.selection)
self.lab.grid()
self.navigation.grid()
def selection(self,event):
self.lab['text']=self.fichierSelect.get()
class MonTreeview(Treeview):
def __init__(self, path):
Treeview.__init__(self)
self.ysb=Scrollbar(self, orient='vertical', command=self.yview)
self.xsb=Scrollbar(self, orient='horizontal', command=self.xview)
self.configure(yscroll=self.ysb.set, xscroll=self.xsb.set)
self.abspath = os.path.abspath(path)
root_node = self.insert('', 'end', text=self.abspath, open=True)
self.process_directory(root_node, self.abspath)
self.ysb.grid(row=0, column=1, sticky='ns')
self.xsb.grid(row=1, column=0, sticky='ew')
def process_directory(self, parent, path):
for p in os.listdir(path):
abspath = os.path.join(path, p)
isdir = os.path.isdir(abspath)
oid = self.insert(parent, 'end', text=p, open=False)
if isdir:
self.process_directory(oid, abspath)
if __name__=='__main__':
path="/home/nicolas/Mind/"
MaFenetre(path).mainloop() |
Partager