0

Please refrain from using Class, ___init____, etc because these things are all beyond my knowledge and understanding. Essentially if somebody could show me how to do this in the same margin/indentation level of code, that would be greatly appreciated.

Using python3.4.3 on windows

Thanks

Ryan Mansuri
  • 99
  • 2
  • 3
  • 6
  • Possible duplicate of [Command for clicking on the items of a Tkinter Treeview widget?](http://stackoverflow.com/questions/3794268/command-for-clicking-on-the-items-of-a-tkinter-treeview-widget) – oystein-hr Jan 17 '16 at 08:21
  • Ive tried several times to understand that chunk of code, however im requesting somebody to show to me exactly how to click an item within the same indentation level; so as written above, no Class/functions. Please and thanks – Ryan Mansuri Jan 17 '16 at 15:16
  • example use Class to keep code cleaner but it doesn't matter. You can do it in the same way without class. You have to get function from example and assign to mouse button - that is all. You can do it. – furas Jan 17 '16 at 15:28

1 Answers1

3

oystein-hr gaves you solution and you can use it as normal function.

Example base on Byan Oakley example code:
https://stackoverflow.com/a/3794505/1832058

and Bryan Oakley suggestion to use <<TreeviewSelect>>: https://stackoverflow.com/a/12064135/1832058

import tkinter as tk
from tkinter import ttk

def OnDoubleClick(event):
    item = tree.selection()
    print('item:', item)
    print('event:', event)
    item = tree.selection()[0]

    print("you clicked on", tree.item(item,"text"))

root = tk.Tk()
tree = ttk.Treeview()
tree.pack()

for i in range(10):
    tree.insert("", "end", text="Item %s" % i)

#tree.bind("<Double-1>", OnDoubleClick) # double click
#tree.bind("<Button-1>", OnDoubleClick) # single click
tree.bind("<<TreeviewSelect>>", OnDoubleClick) # single click, without "index out of range" error

root.mainloop()

No row "act as a button" because you can click it to run function.

Community
  • 1
  • 1
furas
  • 134,197
  • 12
  • 106
  • 148