I’ve looked at several posts regarding this and they’ve done the following
-The output i get is blank
-The output i get is the id, which is practically useless unless somebody can show me how to manipulate it
-No output at all
i just want to be able to click an item in treeview, and instantly be given the text i just clicked
JavaScript
x
6
1
def OnDoubleClick(event):
2
item = course1_assessments.focus()
3
print (item)
4
5
course1_assessments.bind("<<TreeviewSelect>>", OnDoubleClick)
6
This code gives me ‘I001’ if i click the first item, and ‘I002’ when i click the second; id assume these are column values in the tree, but still useless to me
Advertisement
Answer
You can get a list of the selected items with the selection
method of the widget. It will return a list of item ids. You can use the item
method to get information about each item.
For example:
JavaScript
1
24
24
1
import tkinter as tk
2
from tkinter import ttk
3
4
class App:
5
def __init__(self):
6
self.root = tk.Tk()
7
self.tree = ttk.Treeview()
8
self.tree.pack(side="top", fill="both")
9
self.tree.bind("<<TreeviewSelect>>", self.on_tree_select)
10
11
for i in range(10):
12
self.tree.insert("", "end", text="Item %s" % i)
13
14
self.root.mainloop()
15
16
def on_tree_select(self, event):
17
print("selected items:")
18
for item in self.tree.selection():
19
item_text = self.tree.item(item,"text")
20
print(item_text)
21
22
if __name__ == "__main__":
23
app = App()
24