Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98977

link a treeview to a list

Newsgroups comp.lang.python
Date 2015-11-18 08:34 -0800
Message-ID <650de6af-2ae1-4218-8d14-d06c84fc5cc9@googlegroups.com> (permalink)
Subject link a treeview to a list
From durozoyp@gmail.com

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

link a treeview to a list durozoyp@gmail.com - 2015-11-18 08:34 -0800

csiph-web