["c:","c:/folder","c:/folder2","c:/folder/file.txt","c:/folder/folder3","c:/folder/folder3/file2.txt","c:/folder2/file3.txt"]
I want with this example that my tree seems like this:
c: |folder ||file.txt ||folder3 |||file2.txt |folder2 ||file3.txt
I have tried for loops but it doesnt work.
import tkinter as tk
from tkinter import ttk
def finder(sys):
def tree_with_sys(parent: tk.Tk, system: list):
tree = ttk.Treeview(parent)
#Place where I don't know what to do
return tree
win_finder = tk.Tk()
win_finder.geometry("1800x1000+0+0")
win_finder.title("Finder")
tree = tree_with_sys(win_finder, sys)
tree.pack()
win_finder.mainloop()
I think that recursives functions may help... maybe ? Thanks for help

I have solved your problem. I have never used
tkintermyself but your problem seems simple enough so I decided to give it a try and solve it.It is simple. First of all, you don't need to create
win_finder,treeis its own window, you are creating two windows here. And the window is too big for what you used as examples. I removed that part without affecting the functionality.Now your code gives me a great starting point,
tree = ttk.Treeview(tk.Tk()); tree.pack(); tree.main_loop()are what is needed to get the code running.Now how to add the nodes? I just created a new file in Visual Studio Code, and inspected the attributes of
tree, we need to useinsertmethod ofTreeviewclass instances here.inserttakes many arguments, the ones that are relevant here are positional argumentsparentandindex, and optional argumenttext.textis what is displayed,''asparentcreates are top level node, else the new node is inserted to the specified parent, andindexis where the node should be inserted to,'end'means the node is appended to the end.To get what you want, we first need to split the file names by
'/'to get the leaves, and we can then loop through each first n levels to check if the corresponding node has been created, we keep track of the nodes in adictand create the new node if needed by retrieving the identifier of the parent node and add new node using theinsertmethod.