From 912e4068e3bdf9b3bf0feed225995904e4c710c5 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Fri, 19 Jul 2019 20:14:37 -0400 Subject: [PATCH 1/2] Two new Table.Update parameters - alternating_row_color and row_colors. Addition of doc strings for Table.Update --- PySimpleGUI.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/PySimpleGUI.py b/PySimpleGUI.py index b67dfc56..5a1ea3b8 100644 --- a/PySimpleGUI.py +++ b/PySimpleGUI.py @@ -4409,16 +4409,17 @@ class Table(Element): size=size, pad=pad, key=key, tooltip=tooltip, visible=visible) return - def Update(self, values=None, num_rows=None, visible=None, select_rows=None): + def Update(self, values=None, num_rows=None, visible=None, select_rows=None, alternating_row_color=None, row_colors=None): """ Changes some of the settings for the Table Element. Must call `Window.Read` or `Window.Finalize` prior - :param values: - :param num_rows: - :param visible: (bool) control visibility of element - :param select_rows: + :param values: List[List[Any]] A new 2-dimensional table to show + :param num_rows: (int) How many rows to display at a time + :param visible: (bool) if True then will be visible + :param select_rows: List[int] List of rows to select as if user did + :param alternating_row_color: (str) the color to make every other row + :param row_colors: List[Tuple[int, str]] list of tuples of (row, color). Changes the colors of listed rows to the color provided """ - if values is not None: children = self.TKTreeview.get_children() for i in children: @@ -4444,6 +4445,20 @@ class Table(Element): rows_to_select = [i+1 for i in select_rows] self.TKTreeview.selection_set(rows_to_select) + if alternating_row_color is not None: # alternating colors + self.AlternatingRowColor = alternating_row_color + + if self.AlternatingRowColor is not None: + for row in range(0, len(self.Values), 2): + self.TKTreeview.tag_configure(row, background=self.AlternatingRowColor) + if row_colors is not None: # individual row colors + self.RowColors = row_colors + for row_def in self.RowColors: + if len(row_def) == 2: # only background is specified + self.TKTreeview.tag_configure(row_def[0], background=row_def[1]) + else: + self.TKTreeview.tag_configure(row_def[0], background=row_def[2], foreground=row_def[1]) + def treeview_selected(self, event): """ From 6c620efc832ae967e85f28e53bc941d5668a6ad0 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Fri, 19 Jul 2019 21:21:55 -0400 Subject: [PATCH 2/2] Exposed TOOLTIP_BACKGROUND_COLOR --- PySimpleGUI.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PySimpleGUI.py b/PySimpleGUI.py index 5a1ea3b8..07b4b7f2 100644 --- a/PySimpleGUI.py +++ b/PySimpleGUI.py @@ -200,6 +200,7 @@ DEFAULT_WINDOW_LOCATION = (None, None) MAX_SCROLLED_TEXT_BOX_HEIGHT = 50 DEFAULT_TOOLTIP_TIME = 400 DEFAULT_TOOLTIP_OFFSET = (0, -20) +TOOLTIP_BACKGROUND_COLOR = "#ffffe0" #################### COLOR STUFF #################### BLUES = ("#082567", "#0A37A3", "#00345B") PURPLES = ("#480656", "#4F2398", "#380474") @@ -465,7 +466,7 @@ class ToolTip: self.tipwindow.wm_attributes("-topmost", 1) label = ttk.Label(self.tipwindow, text=self.text, justify=tk.LEFT, - background="#ffffe0", relief=tk.SOLID, borderwidth=1) + background=TOOLTIP_BACKGROUND_COLOR, relief=tk.SOLID, borderwidth=1) label.pack() def hidetip(self):