Skip to content

Commit b4253b4

Browse files
authored
Merge pull request #44 from FoamyGuy/text_coloring
save color even if text doesn't exist yet for index
2 parents f32f3ca + 431b933 commit b4253b4

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

adafruit_matrixportal/matrixportal.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,16 @@ def set_text_color(self, color, index=0):
254254
:param index: Defaults to 0.
255255
256256
"""
257-
if self._text[index]:
258-
color = self.html_color_convert(color)
259-
self._text_color[index] = color
260-
self._text[index].color = color
257+
if 0 <= index < len(self._text_color):
258+
self._text_color[index] = self.html_color_convert(color)
259+
if self._text[index] is not None:
260+
self._text[index].color = self._text_color[index]
261+
else:
262+
raise IndexError(
263+
"index {} is out of bounds. Please call add_text() and set_text() first.".format(
264+
index
265+
)
266+
)
261267

262268
def set_text(self, val, index=0):
263269
"""Display text, with indexing into our list of text boxes.

0 commit comments

Comments
 (0)