Merge pull request #6483 from PySimpleGUI/Dev-latest

Added highlight colors to the set_index_color method. Parms highlight…
This commit is contained in:
PySimpleGUI 2023-08-21 17:31:23 -04:00 committed by GitHub
commit 4a5e2316e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 22 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
version = __version__ = "4.61.0.195 Unreleased" version = __version__ = "4.61.0.196 Unreleased"
_change_log = """ _change_log = """
Changelog since 4.60.0 released to PyPI on 8-May-2022 Changelog since 4.60.0 released to PyPI on 8-May-2022
@ -462,6 +462,9 @@ _change_log = """
Added Listbox.select_index and Listbox.set_index_color Added Listbox.select_index and Listbox.set_index_color
4.61.0.195 4.61.0.195
New Udemy Coupon New Udemy Coupon
4.61.0.196
Added highlight colors to the set_index_color method. Parms highlight_text_color & highlight_background_color control changing the highlight colors
""" """
@ -3332,7 +3335,6 @@ class Listbox(Element):
return value return value
def select_index(self, index, highlight_text_color=None, highlight_background_color=None): def select_index(self, index, highlight_text_color=None, highlight_background_color=None):
""" """
Selects an index while providing capability to setting the selected color for the index to specific text/background color Selects an index while providing capability to setting the selected color for the index to specific text/background color
@ -3359,22 +3361,12 @@ class Listbox(Element):
self.TKListbox.selection_set(index, index) self.TKListbox.selection_set(index, index)
if highlight_text_color is not None: if highlight_text_color is not None:
text_color = highlight_text_color self.widget.itemconfig(index, selectforeground=highlight_text_color)
else:
text_color = None
if highlight_background_color is not None: if highlight_background_color is not None:
background_color = highlight_background_color self.widget.itemconfig(index, selectbackground=highlight_background_color)
else:
background_color = None
if text_color is not None:
self.widget.itemconfig(index, selectforeground=text_color)
if background_color is not None:
self.widget.itemconfig(index, selectbackground=background_color)
def set_index_color(self, index, text_color=None, background_color=None): def set_index_color(self, index, text_color=None, background_color=None, highlight_text_color=None, highlight_background_color=None):
""" """
Sets the color of a specific item without selecting it Sets the color of a specific item without selecting it
@ -3384,6 +3376,10 @@ class Listbox(Element):
:type text_color: (str) :type text_color: (str)
:param background_color: color of the background for this item :param background_color: color of the background for this item
:type background_color: (str) :type background_color: (str)
:param highlight_text_color: color of the text when this item is selected.
:type highlight_text_color: (str)
:param highlight_background_color: color of the background when this item is selected
:type highlight_background_color: (str)
""" """
if not self._widget_was_created(): # if widget hasn't been created yet, then don't allow if not self._widget_was_created(): # if widget hasn't been created yet, then don't allow
@ -3397,11 +3393,15 @@ class Listbox(Element):
_error_popup_with_traceback('Index {} is out of range for Listbox.set_index_color. Max allowed index is {}.'.format(index, len(self.Values)-1)) _error_popup_with_traceback('Index {} is out of range for Listbox.set_index_color. Max allowed index is {}.'.format(index, len(self.Values)-1))
return return
if text_color is not None: if text_color is not None:
self.widget.itemconfig(index, fg=text_color) self.widget.itemconfig(index, fg=text_color)
if background_color is not None: if background_color is not None:
self.widget.itemconfig(index, bg=background_color) self.widget.itemconfig(index, bg=background_color)
if highlight_text_color is not None:
self.widget.itemconfig(index, selectforeground=highlight_text_color)
if highlight_background_color is not None:
self.widget.itemconfig(index, selectbackground=highlight_background_color)