-1

I wrote a program in python 3.6.4 using tkinter library

from tkinter import ttk
import tkinter

root = tkinter.Tk()

tree = ttk.Treeview(root)

tree["columns"]=("one","two")
tree.column("one", width=100 )
tree.column("two", width=100)
tree.heading("one", text="coulmn A")
tree.heading("two", text="column B")

tree.insert("" , 0,    text="Line 1", values=("1A","1b"))

id2 = tree.insert("", 1, "dir2", text="Dir 2")
tree.insert(id2, "end", "dir 2", text="sub dir 2", values=("2A","2B"))

##alternatively:
tree.insert("", 3, "dir3", text="Dir 3")
tree.insert("dir3", 3, text=" sub dir 3",values=("3A"," 3B"))

tree.pack()
root.mainloop()

I want add button on treeview, and I do not how.

Oluwafemi Sule
  • 36,144
  • 1
  • 56
  • 81
naghi
  • 253
  • 3
  • 8
  • 15
  • I am not sure if this is possible. According to this: https://stackoverflow.com/questions/16755176/tkinter-insert-a-combobox-inside-a-treeview-widget The treeview widget doesn't support embedded widgets. – SuperKogito Oct 07 '17 at 19:24

1 Answers1

1

The comment by @kogito is correct: no embedded widgets. However, you can make a cell act like a widget by binding mouse clicks to a function that calls the .identify_region, .identify_row, and .identify_column methods. (I might use right clicks to avoid interfering with normal left click functions.) If you want certain row to respond to clicks, one can use tags and tag_bind.

Tkinter.ttk Treeview reference

Tcl/tk treeview reference

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52