2

I would like to have a treeview with all the elements anchored to the left, with no heading and with the little plus button that expands the subvalues. For some reason I dont get the three things to work at once.

Here's my code:

import tkinter as tk
from tkinter import ttk

list1 = ["N_1", "N_13", "N_17"]
list2 = ["N_8", "N_3", "N_5", "N_19"]

root = tk.Tk()
frame = tk.Frame(root)
frame.place(x=0, y=0, relwidth=1, relheight=1)
tree = ttk.Treeview(frame)
tree["show"] = "tree"
tree.place(x=0, y=0, relwidth=1, relheight=1)
tree['columns'] = ["Col1"]
tree.column("Col1", anchor='w') #n, ne, e, se, s, sw, w, nw, or center
tree.insert("", "end" , values= "Num1")
for i in list1:
    tree.insert("", "end" , values= i)
id = tree.insert("", "end")
for i in list2:
    tree.insert(id, "end", values=i)

root.mainloop()

The code shown gives you this

If you change the show attribute to "headings"

Then the result is this

  • Ive allready edited my question to make it more understandable – Daniel Casasampera May 25 '19 at 11:09
  • I'm not sure I understand what you want. Could you add a link to an image illustrating what you want it would look like? You might also be able to accomplish this by inserting a layout in pure text into your question. – martineau May 25 '19 at 18:43
  • 1
    Ive put some images to make it more clear. What I would like to get is the result of image 2 but with no headings and with the little plus button of image 1 – Daniel Casasampera May 26 '19 at 00:10

1 Answers1

0

You can pass anchor as a parameter when you create your tree columns.

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
tree = ttk.Treeview(root)
header = ('size',)
tree['columns'] = header
tree.column('size', width=100, anchor='w') #n, ne, e, se, s, sw, w, nw, or center
tree.heading('size', text='Size')
tree.insert("",0,values=("Left",))
tree.pack()

root.mainloop()
Henry Yik
  • 22,275
  • 4
  • 18
  • 40