Hello I would like to do something like that, can you suggest a function that will allow me to do this? Thanks
What I have on the window:
- GrandParents
- Parents
Child1
Child2
- Parents2
Child3
- GrandParents2
Children
...
What I would like to get in the console:
GrandParents_Parents_Child1
GrandParents_Parents_Child2
GrandParents_Parents2_Child3
GrandParents2_Children
...
My code:
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.title("Treeview")
entry = tk.Entry(root)
tv = ttk.Treeview()
menu = tk.Menu(root, tearoff = False)
def add():
if not tv.exists(entry.get()) and entry.get() != "":
if tv.selection() == ():
tv.insert('', 'end', entry.get(), text=entry.get())
else:
tv.insert(tv.selection()[0], 'end', entry.get(), text=entry.get())
def popup(event):
menu.tk_popup(event.x_root, event.y_root)
def unselect(event):
if len(tv.selection()) > 0:
tv.selection_remove(tv.selection()[0])
menu.add_command(label="Add", command=add)
tv.bind("<Button-3>", popup)
tv.bind("<Button-1>", unselect)
tv.pack()
entry.pack()
root.mainloop()