Python Forum
Cannot get tree.select to work for the life of me.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot get tree.select to work for the life of me.
#1
After finally getting my Tkinter Tree setup I have begun creating the rest of the layout for the GUI. Upon creating the rest of the layout, I knew I was going to have to setup a DoubleClick function for selecting items in the tree. The problem I am encountering is that I cannot get the function to work at all. I figured out I needed to identify the item id's so I can call the items using tree.selection, but the most I've gotten to work is that no error are returned, but during debugging, no value is assigned either. I've literally exhausted my resources because I have tried so many different method (more than I'd like to list). My code setup currently is as follows:

class ViewDataFrame(tk.Frame):

    def __init__(self, parent, container):
        tk.Frame.__init__(self, parent)

        tk_table = ttk.Treeview(self, columns=imp_df.columns.values)

        for each_record in range(len(imp_df)):
            tk_table.insert("", tk.END, values=list(imp_df.loc[each_record]))

        tk_table.pack(side='top', fill='x')

        scrollbar = tk.Scrollbar(self, orient="horizontal",
                                 command=tk_table.xview)

        scrollbar.pack(side='top', fill='x')

        tk_table.configure(xscrollcommand=scrollbar.set)

    def on_click(event):
        curItem = tk_table.identify("item", event.x, event.y)
        print(tk_table.item(curItem)["text"])

    tk_table.bind("<<TreeviewSelect>>", on_click)
This is just a single frame out of the entire program. I have cut out the sensitive data therefore apologies if the code looks unorganized.

def on_click(event):
        curItem = tk_table.identify("item", event.x, event.y)
        print(tk_table.item(curItem)["text"])
^^This method is what returns no error, but doesn't assign a value to 'curItem' either.

Edit: I always do as much research as I can first to avoid having to post too many questions, but this was a question I was unable to find an answer for directly.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020