background color ignored by sub box label widget
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 827
- Avg merge
- 9h 45m
- Merged PRs (30d)
- 58
Description
If I set a box with a background color, label widget children of that box are displayed correctly with the specified background.
However, if a child is another box that contains a label, then the background colour of the outer box is not propagated to the inner boxes.
Is that the expected behaviour?
I would have thought the I could set a background colour of a box and then all sub-widgets (no matter how deep in sub-boxes) would also be rendered with the same background colour.
```python
#!/usr/bin/env python
import toga
from toga.style import Pack
from toga.style.pack import ( COLUMN, ROW, CENTER )
#!============================================================================
class Test_App( toga.App ) :
def startup( self ) :
#! Create the main window
self.main_window = toga.MainWindow( title=self.name )
body_box = toga.Box( id = 'days_box',
style = Pack( direction=ROW, flex=0, background_color='yellow' ),
children = [
toga.Label( "XXX" ),
toga.Box( children = [ toga.Label( "YYY" ) ] ),
toga.Label( "ZZZ" ),
],
)
main_box = toga.Box( id = 'main_box',
style = Pack( direction=COLUMN, flex=0 ),
children = [ body_box ],
)
self.main_window.content = main_box
#! Show the main window
self.main_window.show()
#!============================================================================
def main() :
return Test_App( 'Test App', 'au.com.etrix.test_app' )
```
Note how label "YYY" does not have the specified background colour. It has the default system colour.

Contributor guide
Research direction
Reproduce the issue with the supplied Python example, focusing on the nested toga.Box and its toga.Label child. Trace how Box and Label styles handle background_color, then add a regression test showing whether nested labels inherit the outer box color; done means the expected behavior is documented and consistently verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100