@@ -57,7 +57,7 @@ class Label(displayio.Group):
57
57
:param int color: Color of all text in RGB hex
58
58
:param double line_spacing: Line spacing of text to display"""
59
59
def __init__ (self , font , * , x = 0 , y = 0 , text = None , max_glyphs = None , color = 0xffffff ,
60
- line_spacing = 1.25 , ** kwargs ):
60
+ background_color = None , line_spacing = 1.25 , ** kwargs ):
61
61
if not max_glyphs and not text :
62
62
raise RuntimeError ("Please provide a max size, or initial text" )
63
63
if not max_glyphs :
@@ -71,7 +71,14 @@ def __init__(self, font, *, x=0, y=0, text=None, max_glyphs=None, color=0xffffff
71
71
self .y = y
72
72
73
73
self .palette = displayio .Palette (2 )
74
- self .palette .make_transparent (0 )
74
+ if background_color is not None :
75
+ self .palette [0 ] = background_color
76
+ self .palette .make_opaque (0 )
77
+ self ._transparent_background = False
78
+ else :
79
+ self .palette [0 ] = 0
80
+ self .palette .make_transparent (0 )
81
+ self ._transparent_background = True
75
82
self .palette [1 ] = color
76
83
77
84
bounds = self .font .get_bounding_box ()
@@ -168,6 +175,24 @@ def color(self):
168
175
def color (self , new_color ):
169
176
self .palette [1 ] = new_color
170
177
178
+ @property
179
+ def background_color (self ):
180
+ """Color of the background as an RGB hex number."""
181
+ if not self ._transparent_background :
182
+ return self .palette [0 ]
183
+ return None
184
+
185
+ @background_color .setter
186
+ def background_color (self , new_color ):
187
+ if new_color is not None :
188
+ self .palette [0 ] = new_color
189
+ self .palette .make_opaque (0 )
190
+ self ._transparent_background = False
191
+ else :
192
+ self .palette [0 ] = 0
193
+ self .palette .make_transparent (0 )
194
+ self ._transparent_background = True
195
+
171
196
@property
172
197
def text (self ):
173
198
"""Text to display."""
0 commit comments