Skip to content

Commit 4948e4f

Browse files
committed
Table Element - addition of cols_justification parameter - list of strings that indicate how each column should be justified
1 parent 39e729c commit 4948e4f

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

PySimpleGUI.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/python3
22

3-
version = __version__ = "4.60.0.20 Unreleased"
3+
version = __version__ = "4.60.0.21 Unreleased"
44

55
_change_log = """
66
Changelog since 4.60.0 released to PyPI on 8-May-2022
@@ -52,6 +52,8 @@
5252
PySimpleGUI Anniversary sale on Udemy course coupon
5353
4.60.0.20
5454
Fix for bind_return_key - if a button has been disabled, then the event shouldn't be generated for the return key being pressed
55+
4.60.0.21
56+
Added cols_justification for Table element - list or tuple of strings that indicates how each column should be justified
5557
"""
5658

5759
__version__ = version.split()[0] # For PEP 396 and PEP 345
@@ -8531,7 +8533,7 @@ def update(self, menu_definition=None, visible=None):
85318533
# ---------------------------------------------------------------------- #
85328534
class Table(Element):
85338535

8534-
def __init__(self, values, headings=None, visible_column_map=None, col_widths=None, def_col_width=10,
8536+
def __init__(self, values, headings=None, visible_column_map=None, col_widths=None, cols_justification=None, def_col_width=10,
85358537
auto_size_columns=True, max_col_width=20, select_mode=None, display_row_numbers=False, num_rows=None,
85368538
row_height=None, font=None, justification='right', text_color=None, background_color=None,
85378539
alternating_row_color=None, selected_row_colors=(None, None), header_text_color=None, header_background_color=None, header_font=None, header_border_width=None, header_relief=None,
@@ -8548,6 +8550,8 @@ def __init__(self, values, headings=None, visible_column_map=None, col_widths=No
85488550
:type visible_column_map: List[bool]
85498551
:param col_widths: Number of characters that each column will occupy
85508552
:type col_widths: List[int]
8553+
:param cols_justification: Justification for EACH column. Is a list of strings with the value 'l', 'r', 'c' that indicates how the column will be justified. Either no columns should be set, or have to have one for every colun
8554+
:type cols_justification: List[str] or Tuple[str] or None
85518555
:param def_col_width: Default column width in characters
85528556
:type def_col_width: (int)
85538557
:param auto_size_columns: if True columns will be sized automatically
@@ -8645,6 +8649,7 @@ def __init__(self, values, headings=None, visible_column_map=None, col_widths=No
86458649
self.ColumnHeadings = headings
86468650
self.ColumnsToDisplay = visible_column_map
86478651
self.ColumnWidths = col_widths
8652+
self.cols_justification = cols_justification
86488653
self.MaxColumnWidth = max_col_width
86498654
self.DefaultColumnWidth = def_col_width
86508655
self.AutoSizeColumns = auto_size_columns
@@ -16377,7 +16382,19 @@ def _add_expansion(element, row_should_expand, row_fill_direction):
1637716382
width = element.ColumnWidths[i] * _char_width_in_pixels(font)
1637816383
except:
1637916384
width = element.DefaultColumnWidth * _char_width_in_pixels(font)
16380-
treeview.column(heading, width=width, minwidth=10, anchor=anchor, stretch=element.expand_x)
16385+
if element.cols_justification is not None:
16386+
try:
16387+
if element.cols_justification[i].startswith('l'):
16388+
col_anchor = tk.W
16389+
elif element.cols_justification[i].startswith('r'):
16390+
col_anchor = tk.E
16391+
else:
16392+
col_anchor = tk.CENTER
16393+
except: # likely didn't specify enough entries (must be one per col)
16394+
col_anchor = anchor
16395+
else:
16396+
col_anchor = anchor
16397+
treeview.column(heading, width=width, minwidth=10, anchor=col_anchor, stretch=element.expand_x)
1638116398
# Insert values into the tree
1638216399
for i, value in enumerate(element.Values):
1638316400
if element.DisplayRowNumbers:
@@ -25049,4 +25066,4 @@ def main():
2504925066
exit(0)
2505025067
main()
2505125068
exit(0)
25052-
def get_signature(): return b'\x8e\x1a\xf9\x99\x98z\x8fG\xf5G]\xa9\x08\xcc\xb0!\x88\xa5\x1ax\xd2%\xe7\x18\x87\xce\xad!\x9a\xff\x91z\x98\x84\x00r\xe8\xa3\x1212\xd5#\xe5\xb7\xc1\x01\xcb\xf5m\x0f\xc3\x02\x08\xf5c\x16\x12\x16\xf3\x99\xd1h\xe3\x05\xd4\xccS]\x15\x9a}\x9fTr\x965\xd5S\xce\x93#|x\xac7\x9a#\x1d\x90\x97\xcc\xfa\xe2w\x00\xf8\xd0\xeb\x10\x8a\x81\r\xffO}\x17\x95\xbc\x806\xaf>8\xc9\xd1\xe3\xc9v\x9a\x05$\xa2\x90\xa6\xe9F$'
25069+
def get_signature(): return b"\x81\xbfU'\xa1*\x8f\xc3\x04\xb5i\xafE|m \xdcK\x08\xdf\x0f\xe9\xb7/\x9e\xadW\x03j\x82\x88\xa5\x81f\xfc\xe2/]u\xbd\x9e\x8d\xb3\xcc]\xa5>=y\xc8d\n\x184\xb3\x9f\x15\x1b^,\xdc\xa3\x8aH\x8ama#\xfc\xbb\x88\xf2\x8b\xd4\x05o'\xf1w$-t\xbb\xedj\x93\xc1C\xdb\xc9\xa9&\x00\xeef\xa2Xu[\x94\x8dA\x1ey\x83\x0f>\xfd\xec\xad\x9a\x83\xbf\x1c\x99\xd7\x80\xc9|@6\x08\xcf\r\x00\x05$1"

0 commit comments

Comments
 (0)