如何仅在表的“名称”列中添加名称?

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

我正在使用tkinter创建一个狗顶级王牌风格游戏,并且只需要在名称列中显示名称,但它会在所有列中传播名称

labelText.set("These are your cards")
tree = ttk.Treeview(root,columns=("Name","Exercise","Intelligence","Friendliness","Drool"))
tree["show"]= "headings"
namecol = tree.heading("Name", text="Name")
tree.heading("Exercise", text="Exercise")
tree.heading("Intelligence", text="Intelligence")
tree.heading("Friendliness", text="Friendliness")
tree.heading("Drool", text="Drool")

tree.grid(row=6,column=0,columnspan=5)

lbl = tkinter.Label(root, text="Your Cards")
lbl.grid(column=0, row=5, columnspan=5)


#creates a list with each dog in it
dogs = []

with open("dogs.txt", "rt") as in_file:
    for dog in in_file:
        dogs.append(dog)


for value in dogs:
    tree.insert("", "0", value=dogs)

我最后用它在所有列而不是名称列上显示文本文件,而不是仅显示名称

python tkinter treeview
1个回答
1
投票
for value in dogs:
    tree.insert("", "0", value=dogs)

for value in dogs:
    tree.insert("", "0", value=value)
© www.soinside.com 2019 - 2024. All rights reserved.