Skip to content

Commit 229b3f4

Browse files
authored
Merge pull request #235 from FoamyGuy/fix_empty_textbox_init
fix for TextBox when initialized with an empty text
2 parents 2aefd1a + 437f6a2 commit 229b3f4

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

adafruit_display_text/text_box.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,24 @@ def __init__(
9494
font,
9595
)
9696

97+
text_empty = False
98+
if not kwargs.get("text", ""):
99+
text_empty = True
100+
kwargs["text"] = " "
101+
97102
super().__init__(font, **kwargs)
98103

99-
self._text = "\n".join(self.lines)
100-
self._text = self._replace_tabs(self._text)
101-
self._original_text = self._text
104+
if text_empty:
105+
self._full_text = ""
106+
107+
self._full_text = "\n".join(self.lines)
108+
self._full_text = self._replace_tabs(self._full_text)
109+
self._original_text = self._full_text
102110

103111
# call the text updater with all the arguments.
104112
self._reset_text(
105113
font=font,
106-
text=self._text,
114+
text=self._full_text,
107115
line_spacing=self._line_spacing,
108116
scale=self.scale,
109117
)

0 commit comments

Comments
 (0)