-2

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

  • you may need to use recursion to run the same code for subfolder. OR you can use `os.walk()` to work with all subfolders. – furas Jul 13 '21 at 16:18
  • if you have list then use `for`-loop to repeate it for every folder on list. – furas Jul 13 '21 at 16:19
  • better show minimal working code - it will be simpler to create solution. – furas Jul 13 '21 at 16:20
  • Possible duplicate of [this post](https://stackoverflow.com/questions/16746387/display-directory-content-with-tkinter-treeview-widget) –  Jul 14 '21 at 07:52

1 Answers1

2

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

furas
  • 134,197
  • 12
  • 106
  • 148