diff --git a/adafruit_matrixportal/matrixportal.py b/adafruit_matrixportal/matrixportal.py index 9daa217..8d357f7 100755 --- a/adafruit_matrixportal/matrixportal.py +++ b/adafruit_matrixportal/matrixportal.py @@ -254,10 +254,16 @@ def set_text_color(self, color, index=0): :param index: Defaults to 0. """ - if self._text[index]: - color = self.html_color_convert(color) - self._text_color[index] = color - self._text[index].color = color + if 0 <= index < len(self._text_color): + self._text_color[index] = self.html_color_convert(color) + if self._text[index] is not None: + self._text[index].color = self._text_color[index] + else: + raise IndexError( + "index {} is out of bounds. Please call add_text() and set_text() first.".format( + index + ) + ) def set_text(self, val, index=0): """Display text, with indexing into our list of text boxes.