Search code examples
pythontkintertreeview

python tkinter - Make a treeview widget for Directory display with a list of folders


so what i want to say is that i want a tkinter treeview widget which shows all files and sub-folders in the directory.. and that too with viewing folders from a list of folders..

I have till now tried that by making a treeview for a single directory but can't make it to view a list of directories


Solution

  • You didn't show code so I don't understand what is your problem.

    If you have list then use for-loop.


    Minimal working code for list with two folders ['test', 'Pobrane']

    I use listdir() but you may need os.walk()

    import os
    import tkinter as tk
    from tkinter import ttk
    
    folders = ['test', 'Pobrane']
    
    root = tk.Tk()
    
    tree = ttk.Treeview()
    tree.pack(fill='both', expand=True)
    
    for folder in folders:
        tree.insert('', 'end', folder, text=folder)
        for name in os.listdir(folder):
            tree.insert(folder, 'end', name, text=name)
            
    root.mainloop()
    

    enter image description here