@@ -57,7 +57,7 @@ class Label(displayio.Group):
5757 :param int color: Color of all text in RGB hex
5858 :param double line_spacing: Line spacing of text to display"""
5959 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 ):
6161 if not max_glyphs and not text :
6262 raise RuntimeError ("Please provide a max size, or initial text" )
6363 if not max_glyphs :
@@ -71,7 +71,14 @@ def __init__(self, font, *, x=0, y=0, text=None, max_glyphs=None, color=0xffffff
7171 self .y = y
7272
7373 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
7582 self .palette [1 ] = color
7683
7784 bounds = self .font .get_bounding_box ()
@@ -168,6 +175,24 @@ def color(self):
168175 def color (self , new_color ):
169176 self .palette [1 ] = new_color
170177
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+
171196 @property
172197 def text (self ):
173198 """Text to display."""
0 commit comments