I created a ttk/Treeview Widget in Tkinter using Python 3. I would like to connect an object to its name which is listed in the tree view. To illustrate this I created following example.
import tkinter as tk
from tkinter import ttk
class myclass:
def __init__(self, name, value):
self.name=name
self.value=value
class maintree(ttk.Treeview):
def __init__(self, master):
super().__init__(master)
self.master = master
self.my_objects= [myclass("object"+str(_), _) for _ in range(1,11)]
for my_object in self.my_objects:
self.insert("", "end", text=my_object.name)
def main():
root = tk.Tk()
maintree(root).grid()
root.mainloop()
if __name__ == '__main__':
main()
In this example I would like to get the my_class instance corresponding to the selected name in the treeview to do something (ie, display the value of the currently selected my_class object).
I only know about the item IDs but I don't know how to connect something to an item itself. I have the feeling that I have some misconception about how treeview is supposed to work.
I appreciate your Help!