简体   繁体   中英

How do I add names only in the Name column of the table?

I'm creating a dog top trumps style game using tkinter and need it too display names only in the Name column but it instead spreads the names across all columns

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)

I end with it displaying the text file over all columns instead of to the name column, instead of it only displaying in names

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

To

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM