python - Command for clicking on the items of a Tkinter Treeview widget? -


i'm creating gui tkinter, , major part of gui 2 treeview objects. need contents of treeview objects change when item (i.e. directory) clicked twice.

if treeview items buttons, i'd able set command appropriate function. i'm having trouble finding way create "on_click" behavior treeview items.

what treeview option, method, etc, enables me bind command particular items , execute command "on_click"?

if want happen when user double-clicks, add binding "<double-1>". since single click sets selection, in callback can query widget find out selected. example:

import tkinter tk tkinter import ttk  class app:     def __init__(self):         self.root = tk.tk()         self.tree = ttk.treeview()         self.tree.pack()         in range(10):             self.tree.insert("", "end", text="item %s" % i)         self.tree.bind("<double-1>", self.ondoubleclick)         self.root.mainloop()      def ondoubleclick(self, event):         item = self.tree.selection()[0]         print("you clicked on", self.tree.item(item,"text"))  if __name__ == "__main__":     app = app() 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -