Tkinter Treeview显示额外的列

问题描述 投票:0回答:1

我正在尝试将滚动条添加到我的树形视图中……但是我无法弄清楚如何使用现有代码来实现它。此外,我在开始时会得到一列额外的内容。谁能告诉我为什么我得到这个?

树视图代码

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

Output of the code

python python-2.7 tkinter treeview
1个回答
0
投票

第一列是树视图的“树”部分。您可以使用show方法将其隐藏,该方法采用的字符串包含单词“ tree”和“ headings”中的一个或两个。如果您不包括“树”,则该列将被隐藏。

tree = ttk.Treeview(formcontainer, show="headings", columns=...)
© www.soinside.com 2019 - 2024. All rights reserved.