link a treeview to a list

durozoyp at gmail.com durozoyp at gmail.com
Wed Nov 18 11:34:43 EST 2015


So I am currently making a little program that generates a list of characters with different stats. Now I would like to display those characters in a list and when the user clicks on one of them display all the stats for that character.

Here is my code for my GUI so far:

class CTABLE:
    def __init__(self, master):

        self.charactersTable = ttk.Treeview(master, selectmode="browse")
        self.charactersTable["show"] = "headings"
        self.charactersTable["columns"]=("Name", "Surname", "Hunger",
            "Fear", "Comfort", "Hapiness")
        self.charactersTable.column("Name", width=100, anchor=E)
        self.charactersTable.heading("Name", text="Name")
        self.charactersTable.column("Surname", width=100, anchor=E)
        self.charactersTable.heading("Surname", text="Surname")
        self.charactersTable.column("Hunger", width=100, anchor=E)
        self.charactersTable.heading("Hunger", text="Hunger")
        self.charactersTable.column("Fear", width=100, anchor=E)
        self.charactersTable.heading("Fear", text="Fear")
        self.charactersTable.column("Comfort", width=100, anchor=E)
        self.charactersTable.heading("Comfort", text="Comfort")
        self.charactersTable.column("Hapiness", width=100, anchor=E)
        self.charactersTable.heading("Hapiness", text="Hapiness")

        for character in characters:
            self.charactersTable.insert("", "end", values=(character.surname, character.name, 
            character.hunger, character.fear, character.comfort,
            character.happiness))
        self.charactersTable.bind("<Double-1>", self.CTClick)
        self.charactersTable.grid(row=1, rowspan=3, column=1)

    def CTClick(self, event):

        item = self.charactersTable.selection()[0]
        print (self.charactersTable.item(item))


My problem is that my CTClick event refers to the line in the treeview object and not the character object itself and I don't know how to fix that



More information about the Python-list mailing list