I am new to python and trying to build a GUI app using PAGE GUI builder I have a treeView widget on my page and here is my function in the support module:
def initTree():
for i in w.prefTreeviewScTrv.get_children():
w.prefTreeviewScTrv.delete(i)
w.prefTreeviewScTrv["columns"]=("one","two","three")
w.prefTreeviewScTrv.column("#0", width=270, minwidth=270, stretch=tk.NO)
w.prefTreeviewScTrv.column("one", width=150, minwidth=150, stretch=tk.NO)
w.prefTreeviewScTrv.column("two", width=400, minwidth=200)
w.prefTreeviewScTrv.column("three", width=80, minwidth=50, stretch=tk.NO)
w.prefTreeviewScTrv.heading("#0",text="Name",anchor=tk.W)
w.prefTreeviewScTrv.heading("one", text="Date modified",anchor=tk.W)
w.prefTreeviewScTrv.heading("two", text="Type",anchor=tk.W)
w.prefTreeviewScTrv.heading("three", text="Size",anchor=tk.W)
# Level 1
w.prefTreeviewScTrv.insert("", 1, "", text="first_file.txt", values=("22-Jun-16 11:25","first file","0.5 KB"))
folder1=w.prefTreeviewScTrv.insert("", 2, "", text="Folder 1", values=("23-Jun-17 11:05","File folder",""))
w.prefTreeviewScTrv.insert("", 3, "", text="text_file.txt", values=("23-Jun-17 11:25","TXT file","1 KB"))
# Level 2
w.prefTreeviewScTrv.insert(folder1, "end", "", text="photo1.png", values=("23-Jun-17 11:28","PNG file","2.6 KB"))
w.prefTreeviewScTrv.insert(folder1, "end", "", text="photo2.png", values=("23-Jun-17 11:29","PNG file","3.2 KB"))
w.prefTreeviewScTrv.insert(folder1, "end", "", text="photo3.png", values=("23-Jun-17 11:30","PNG file","3.1 KB"))
Whenever I run the program, it runs and create the tree columns and heading properly but I get an exception when using the insert method no matter what index I give the item 0 or 1:
Traceback (most recent call last):
File "C:\page\tenders\notebook_support.py", line 127, in <module>
notebook.vp_start_gui()
File "C:\page\tenders\notebook.py", line 30, in vp_start_gui
notebook_support.init(root, top)
File "C:\page\tenders\notebook_support.py", line 115, in init
initTree()
File "C:\page\tenders\notebook_support.py", line 102, in initTree
w.prefTreeviewScTrv.insert("", 1, "", text="first_file.txt", values=("22-Jun-16 11:25","first file","0.5 KB"))
File "C:\Users\ori\AppData\Local\Programs\Python\Python38-32\lib\tkinter\ttk.py", line 1365, in insert
res = self.tk.call(self._w, "insert", parent, index, _tkinter.TclError: Item already exists
what am I doing wrong?
w.prefTreeviewScTrv["columns"]=("one","two","three"): but it seems that there are 4 columns. Have you forgotten the first column?