Tkinter树视图显示了额外的列



我正在尝试将滚动条添加到树视图中。。。但是我不知道如何使用我现有的代码。此外,我在开始时得到了一个额外的专栏。有人能告诉我为什么要买这个吗?

树视图代码

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)

更新功能

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()

代码的输出

第一列是树视图的"树"部分。您可以使用show方法隐藏它,该方法接受一个包含单词"树"one_answers"标题"之一或两者的字符串。如果不包含"树",则该列将被隐藏。

tree = ttk.Treeview(formcontainer, show="headings", columns=...)

最新更新