7

I have a problem with ttk.Treeview in Python 3. If I try to insert item with values that contain newline, treeview crops item and shows only first line of text, instead of making multiline item. Is there any possibility to somehow configure treeview to show it? I would like to avoid implementing new class or add every new line as child item. I know that is it possible to edit Treeview style and for example set 'rowheight', but different items may have different number of newlines. Here is the example code:

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
tv = ttk.Treeview(root, columns=['a','b'])
values = ['one', 'one \ntwo \nthree']
tv.insert('', 'end', values=values)
tv.insert('', 'end', values=values)
tv.pack()

To summary the question is: how to set different rowheight depends of number of newlines in item's values.

voldi
  • 423
  • 2
  • 4
  • 10
  • have you solved the problem? –  Dec 15 '16 at 09:24
  • I have this problem too. No solution after 5 years? – saeedgnu Nov 25 '20 at 11:42
  • As you said, it passed 5 years since I asked this question and actually...I haven't solved it :( Eventually it turned out that maximally there might be 3 lines per cell so I've implemented expand/collapse feature and for exapnding I change rowheight for all cells. It would be better to change style for very row but I don't know if it's possible. – voldi Nov 26 '20 at 13:28

0 Answers0