0
from Tkinter import Tk, Button
import ttk


root = Tk()

tree = ttk.Treeview(root)

tree["columns"]=("one")
tree.column("one" )
# tree.column("two", width=100)


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



def edit():
    x = tree.get_children()
    for item in x: ## Changing all children from root item
        tree.item(item, text="blub", values=("foo", "bar"))

def delete():
    selected_item = tree.selection()[0] ## get selected item
    tree.delete(selected_item)

tree.pack()
button_del = Button(root, text="del", command=delete)
button_del.pack()
button_del = Button(root, text="edit", command=edit)
button_del.pack()

root.mainloop()

I'm trying just to make 1 column using the treeview. But it keeps making one blank one and one that I want it to make. Also when i create 2 columns it makes 3 in total. Not what I want. Tried playing around with the code and no luck. Thanks

Matthew
  • 1
  • 2
  • you do want to make table?? – eyllanesc Dec 23 '16 at 21:38
  • see [Creating a table look-a-like Tkinter](http://stackoverflow.com/questions/11047803/creating-a-table-look-a-like-tkinter/11049650#11049650) and [Display Listbox with columns using Tkinter?](http://stackoverflow.com/a/5287037/1832058) – furas Dec 24 '16 at 03:51
  • 1
    `Treeview` always create first column for `tree`. If you need only one column then you can use this first column without creating other columns - or use standard `Tkinter.Listbox` – furas Dec 24 '16 at 03:55

1 Answers1

0

When creating your treeview, just add show = 'headings' so you would get something like this:

tree = ttk.Treeview(root, show='headings')

Resulting treeview (picture)

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 24 '22 at 22:08