Python Forum

Full Version: tree insert
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I would like to let users enter its name in tk.Entry and goes to sql and by select from sql to appear in TreeView . every time users enter name will appear in TreeView. did I miss something here

 count=0
        for b in row:
            tree.insert(parent='', index='end', iid=count, values=(b))
            count+=1
second line should not be indented.
(Nov-09-2020, 03:19 AM)Larz60+ Wrote: [ -> ]second line should not be indented.

I hope your recommendation it had solved the problem.
I want the insert will goes to Treeview each times
any help would be appreciated


This the code,

count=0
for b in cursor.execute("""SELECT Customer_ID, Customer_Name FROM test_ent""").fetchall():
   self.my_tree.insert(parent='', index='end', iid=count, values=([*b]), tags = ('odd',))
   count=+1
   cnn.commit()
            
   cnn.close()
            
The err is
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-1-9ff313fc081e> in <module>
95
96
---> 97 pp = test()
98
99 pp.win.mainloop()

<ipython-input-1-9ff313fc081e> in __init__(self)
12 self.send_data()
13 self.tree()
---> 14 self.insert_()
15
16 def entr(self):

<ipython-input-1-9ff313fc081e> in insert_(self)
79 count=int
80 for b in cursor.execute("""SELECT Customer_ID, Customer_Name FROM test_ent""").fetchall():
---> 81 self.my_tree.insert(parent='', index='end', iid=count, values=([*b]), tags = ('odd',))
82 count=+1
83 except pyodbc.DatabaseError as err:

~\anaconda3\lib\tkinter\ttk.py in insert(self, parent, index, iid, **kw)
1364 opts = _format_optdict(kw)
1365 if iid is not None:
-> 1366 res = self.tk.call(self._w, "insert", parent, index,
1367 "-id", iid, *opts)
1368 else:

TclError: Item 1 already exists