In Python tkinter treeview I am trying to make a display that will show certain things based on the iid of the selected treeview item, it takes place on a selection event (mouse click) but I cannot get this working:
def tree_click_event (event):
iid = treedisplay.identify(event.x,event.y)
treedisplay = ttk.Treeview(root,selectmode='browse')
treedisplay.bind('<<TreeviewSelect>>', tree_click_event)
treedisplay.pack(side='top', fill='both', expand=1)
error:
TypeError: tree_click_event() missing 1 required positional argument: 'y'
this is condensed down to just creating the tree, packing it in a tkinter window, looking for people familiar with this module to know exactly what I've done wrong
Thank you for your example @BryanOakley, it works to get the text of the item. Is there no way to get the below code working though?
import tkinter as tk
from tkinter import ttk
class App:
def __init__(self):
self.root = tk.Tk()
self.tree = ttk.Treeview()
self.tree.pack(side="top", fill="both")
self.tree.bind("<<TreeviewSelect>>", self.tree_click_event)
for i in range(10):
self.tree.insert("", "end", text="Item %s" % i)
self.root.mainloop()
def tree_click_event(self, event):
iid = self.tree.identify(event.x,event.y)
print (iid)
if __name__ == "__main__":
app = App()