There's no option to wrap text in sg.Tree or ttk.Treeview.
As I know, the only way is to insert '\n' into your text, then it will wrap to next line.
To show all lines in a row, you have to set option row_height large enough to fit all lines.
Here, another problem will be generated for row_height.
- You won't see next line if row height is too small to shown all wrap lines.
- If you set
row_height large enough, you will still see same space occupied if only one line.
- Text will be aligned vertical center
It seems there's no way to set row height for different rows.
example here,
import textwrap
from random import randint, choice
import PySimpleGUI as sg
def wrap(string, lenght=15):
return '\n'.join(textwrap.wrap(string, lenght))
sg.theme('DarkBlue')
sg.set_options(font=('Courier New', 12))
column_width = 15
word = "1234567890"*5
data = [[wrap(word[:randint(1, 50)], column_width) for col in range(4)] for row in range(30)]
header_list = [f'Column {i}' for i in range(4)]
size_list = [column_width+2]*4
layout = [
[sg.Table(
key="-TREE-",
values=data,
headings=header_list,
display_row_numbers=False,
col_widths=size_list,
auto_size_columns=False,
num_rows=10,
row_height=80,
alternating_row_color='green',
)],
]
window = sg.Window('Tree Element Test', layout, finalize=True)
tree = window['-TREE-'].Widget
while True:
event, values = window.read()
if event in (sg.WIN_CLOSED, 'Cancel'):
break
window.close()
Another way is more difficult to implement, using other elements to simulate a tree or a table, like example from Nagaraj Tantri