Repository: kivy/kivy

Issue:
Move background_color property from Button up to Label
Currently it is possible to change `Label` background color with `Canvas` or `texture`, but these are not as convenient to use as `Button.background_color`. It would be nice to have the same property on `Label`.
Support id
We should be able to use id, same as self. and root.
Ids must be local to a template, or global to an application.



Discussion:
I usually just do something like this below...

```
from kivy.app import App
  
class MainApp(App):
    def build(self):
        from kivy.lang import Builder
        return Builder.load_string('''
<Bkclr@Widget>
    background_color: 1, 1, 1, 1
    canvas.before:
        Color:
            rgba: root.background_color
        Rectangle:
            size: self.size
            pos: self.pos

# Now you can simply Mix the Bkclr class with almost any other widget... to give it a background.

<BkLabel@Label+Bkclr>

BkLabel
    text: 'Hello'
    background_color: 1, 0, 0, 1
''')


MainApp().run()

```

This gives you a higher freedom in terms of being able to specify any type of background... Rect or RoundedRect or Ellipse or .... Triangle?....

Maybe we should have behaviours for this ?

`BackgroundRectBehavior` that you can simply mix and Match with any widget? 

The is a reason for currently leaving it open in Kivy you can mix and match stuff in numerous possible ways and Kivy tries to stay out of that decision on what is the right way for a sane default for every possible situation?

Adding Behaviors that people can simply mix and match would be a option that would still preserve the choice while giving a easy way out to developers....

I don't think a behavior is right for this because it's not going to save much over two canvas instructions. I.e. the cost of inheriting from the behavior is not much less than the cost of writing out the color and rectangle instruction under canvas, especially in kv.

Perhaps we should the part of the above example to the label docs?

I do agree though that adding the instruction to label, which is such a basic widget, is probably not a good idea. That's because existing apps use it assuming there's no background so adding one may break them. 

The only way to add this is if the new `background_color` defaults to a alpha value of zero because then it won't break existing programs as it will be completely transparent. But then it would clash with button that doesn't default to alpha zero (I'm assuming) and overwriting kivy properties can lead to subtle issues I think.

So I think the best is to add some example code to label docs showing how to do this.
done !


Resolving patch:
diff --git a/kivy/uix/label.py b/kivy/uix/label.py
--- a/kivy/uix/label.py
+++ b/kivy/uix/label.py
@@ -58,6 +58,30 @@
         text_size: root.width, None
         size: self.texture_size
 
+How to have a custom background color in the label:
+
+.. code-block:: kv
+
+    # Define your background color Template
+    <BackgroundColor@Widget>
+        background_color: 1, 1, 1, 1
+        canvas.before:
+            Color:
+                rgba: root.background_color
+            Rectangle:
+                size: self.size
+                pos: self.pos
+    # Now you can simply Mix the `BackgroundColor` class with almost
+    # any other widget... to give it a background.
+    <BackgroundLabel@Label+BackgroundColor>
+        background_color: 0, 0, 0, 0
+        # Default the background color for this label
+        # to r 0, g 0, b 0, a 0
+    # Use the BackgroundLabel any where in your kv code like below
+    BackgroundLabel
+        text: 'Hello'
+        background_color: 1, 0, 0, 1
+
 Text alignment and wrapping
 ---------------------------
 


Test patch: