1

My TreeView has two columns, name and description. Now for the description, if it is too long, it goes out of column bound and the rest is not visible. I want to know how I can make it go to the next line instead of going out of bounds. I looked at the manual but couldn't find anything that would that. Does anyone know how I can do this?

What happens now:

Name       |      Description         |
TOM        |Activities= Football, Bask| <----- Gone out of bound
BILLY      |Age = 25       

       |

What I expect to happen:

Name       |      Description         |
TOM        |Activities= Football, Bask|
           |etball,Swimming.          |
BILLY      |Age = 25                  |
Cœur
  • 37,241
  • 25
  • 195
  • 267
Tom Boy
  • 599
  • 2
  • 8
  • 14
  • I am not familiar with tkinter but I have used [tabulate](https://pypi.python.org/pypi/tabulate) to good success to achieve similar output to this. In case this helps. – Igor Mar 15 '16 at 20:57

1 Answers1

1

As near as I can tell, Treeview rows, aside from the optional leading icon, are a single line of single-line strings. The only exception I know of is that an embedded \n in the last row will display text after \n on the next line. The following displays too long on the line after the row.

import tkinter as tk
import tkinter.ttk as ttk

root = tk.Tk()
tree = ttk.Treeview(root, columns='test')
tree.pack()
tree.column('#0', width=50)
tree.column('test', width=100, stretch=True)
tree.insert('', 'end', text='one', values=('this item is\ntoo long',))
#tree.insert('', 'end', text='two', values=('short item',))

root.mainloop()

But when the insertion of two is uncommented, short item overwrites too long. One might think of trying is to insert a multiline Label widget, but the answer to this SO question is that only strings, not widgets, are allowed.

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