I am trying to add scroll bar to my tree view... But i cant figure it out how to do it with my existing code. Moreover i am getting an extra column at starting. can anyone tell me why i am getting this?
Tree View Code
tree = ttk.Treeview(formcontainer, columns=("name", "fathersname",
"mothersname","rollno","studentid","contact","email","dob"))
tree.heading('name', text="Student Name", anchor=W)
tree.column("name",minwidth=0,width=100, stretch=NO)
tree.heading('fathersname', text="Father's Name",anchor=CENTER)
tree.column("fathersname",minwidth=0,width=100, stretch=NO)
tree.heading('mothersname', text="Mother's Name", anchor=W)
tree.column("mothersname",minwidth=0,width=100, stretch=NO)
tree.heading('rollno', text="Roll Number", anchor=W)
tree.column("rollno",minwidth=0,width=100, stretch=NO)
tree.heading('studentid', text="Student ID", anchor=W)
tree.column("studentid",minwidth=0,width=100, stretch=NO)
tree.heading('contact', text="Contact", anchor=W)
tree.column("contact",minwidth=0,width=100, stretch=NO)
tree.heading('email', text="Email", anchor=W)
tree.column("email",minwidth=0,width=100, stretch=NO)
tree.heading('dob', text="Date of Birth", anchor=W)
tree.column("dob",minwidth=0,width=100, stretch=NO)
tree.grid(row=0,column=0)
Update Function
def updateview():
conn = sqlite3.connect('example.db')
c = conn.cursor()
t = ('Rahul',)
records = c.execute("SELECT * FROM students")
fatcheddata = tree.get_children()
for elements in fatcheddata:
tree.delete(elements)
print (fatcheddata)
for row in records:
# print(row)
tree.insert("", tk.END, values=row)
conn.commit()
conn.close()
That first column is the "tree" part of the treeview. You can hide it by using the show
method, which takes a string containing one or both of the words "tree" and "headings". If you don't include "tree", that column will be hidden.
tree = ttk.Treeview(formcontainer, show="headings", columns=...)