Tkinter Treeview 显示额外的列
Tkinter Treeview showing extra column
我正在尝试将滚动条添加到我的树视图中...但我不知道如何使用我现有的代码来完成它。此外,我在开始时得到了一个额外的专栏。谁能告诉我为什么我会收到这个?
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()
Output of the code
第一列是树视图的 "tree" 部分。您可以使用 show
方法隐藏它,该方法接受一个包含单词 "tree" 和 "headings" 中的一个或两个的字符串。如果您不包括 "tree",该列将被隐藏。
tree = ttk.Treeview(formcontainer, show="headings", columns=...)
我正在尝试将滚动条添加到我的树视图中...但我不知道如何使用我现有的代码来完成它。此外,我在开始时得到了一个额外的专栏。谁能告诉我为什么我会收到这个?
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()
Output of the code
第一列是树视图的 "tree" 部分。您可以使用 show
方法隐藏它,该方法接受一个包含单词 "tree" 和 "headings" 中的一个或两个的字符串。如果您不包括 "tree",该列将被隐藏。
tree = ttk.Treeview(formcontainer, show="headings", columns=...)