Skip to content

Commit 46cc463

Browse files
authored
Merge pull request PySimpleGUI#4999 from PySimpleGUI/Dev-latest
Tree element - always make col 0 be left justified. Better auto-size …
2 parents bf8d940 + 0551835 commit 46cc463

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

PySimpleGUI.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/python3
2-
version = __version__ = "4.55.1.10 Unreleased"
2+
version = __version__ = "4.55.1.11 Unreleased"
33

44
_change_log = """
55
Changelog since 4.55.1 released to PyPI on 7-Nov-2021
@@ -35,6 +35,11 @@
3535
Don't print the error message about wm_overrideredirect while hiding the master root if running on a Mac.
3636
4.55.1.10
3737
Fix for Tree Element not setting the row height if none is specified. Needed to set to value based on the font used.
38+
4.55.1.11
39+
Tree Element
40+
* Always left justify the first column. This is how it's always worked. tkinter 8.6.12 changed the behavior of the first col. This changes it back
41+
* Better auto-size column. Uses the data as well as the Column header to determine size of column
42+
3843
"""
3944

4045
__version__ = version.split()[0] # For PEP 396 and PEP 345
@@ -15304,10 +15309,19 @@ def _add_expansion(element, row_should_expand, row_fill_direction):
1530415309
height=height,
1530515310
selectmode=element.SelectMode)
1530615311
treeview = element.TKTreeview
15312+
max_widths = {}
15313+
for key, node in element.TreeData.tree_dict.items():
15314+
for i, value in enumerate(node.values):
15315+
max_width = max_widths.get(i, 0)
15316+
if len(str(value)) > max_width:
15317+
max_widths[i] = len(str(value))
15318+
1530715319
for i, heading in enumerate(element.ColumnHeadings): # Configure cols + headings
1530815320
treeview.heading(heading, text=heading)
1530915321
if element.AutoSizeColumns:
15310-
width = min(element.MaxColumnWidth, len(heading) + 1)
15322+
max_width = max_widths.get(i, 0)
15323+
max_width = max(max_width, len(heading))
15324+
width = min(element.MaxColumnWidth, max_width+1)
1531115325
else:
1531215326
try:
1531315327
width = element.ColumnWidths[i]
@@ -15351,7 +15365,7 @@ def add_treeview_data(node):
1535115365
add_treeview_data(node)
1535215366

1535315367
add_treeview_data(element.TreeData.root_node)
15354-
treeview.column('#0', width=element.Col0Width * _char_width_in_pixels(font), anchor=anchor)
15368+
treeview.column('#0', width=element.Col0Width * _char_width_in_pixels(font), anchor=tk.W)
1535515369
# ----- configure colors -----
1535615370
# style_name = str(element.Key) + '.Treeview'
1535715371
style_name = _make_ttk_style_name('.Treeview', element)

0 commit comments

Comments
 (0)