Есть код рекурсивного заполнения TreeView:
import tkinter as tk import tkinter.ttk as ttk class App(tk.Frame): def __init__(self, master, path): tk.Frame.__init__(self, master) self.tree = ttk.Treeview(self, selectmode='browse') self.tree.column('#0', minwidth=300, width=160, stretch=tk.YES) style=ttk.Style(self) style.theme_use("clam") style.configure("Treeview", background="gray", fieldbackground="darkgray", foreground="azure") ysb = ttk.Scrollbar(self, orient='vertical', command=self.tree.yview) xsb = ttk.Scrollbar(self, orient='horizontal', command=self.tree.xview) self.tree.configure(yscroll=ysb.set) self.tree.configure(xscroll=xsb.set) self.tree.heading('#0', text='Текущий каталог', anchor='w') abspath = os.path.abspath(path) root_node = self.tree.insert('', 'end', text=abspath, open=True) self.process_directory(root_node, abspath) self.tree.grid(row=0, column=0) ysb.grid(row=0, column=1, sticky='ns') xsb.grid(row=1, column=0, sticky='ew') self.grid() def process_directory(self, parent, path): for p in os.listdir(path): print("p=", p) abspath = os.path.join(path, p) isdir = os.path.isdir(abspath) oid = self.tree.insert(parent, 'end', text=p, open=False) if isdir: self.process_directory(oid, abspath) root = tk.Tk() path_to_my_project = os.getcwd() app = App(root, path=path_to_my_project) app.mainloop()
Есть у кого-нибудь идеи?