In this video I’ll show you how to change the background and text color of Labels with Kivy and Python.
Changing the background color and text color of a Kivy Label is a little more complicated than changing the color of other widgets. We need to set a Canvas and create a rectangle first.
We’ll also look at making text bold and italic, as well as giving it a shadow background!
Python Code: label_color.py
GitHub Code: label_color.py
from kivy.app import App from kivy.uix.widget import Widget from kivy.properties import ObjectProperty from kivy.lang import Builder # Designate Our .kv design file Builder.load_file('label_color.kv') class MyLayout(Widget): pass class AwesomeApp(App): def build(self): return MyLayout() if __name__ == '__main__': AwesomeApp().run()
Kivy Design Code: label_color.kv
GitHub Code: label_color.kv
<Button> font_size: 32 background_normal: '' background_color: (0,0,1,1) <TextInput> background_color: (150/255,150/255,150/255,1) <MyLayout> BoxLayout: orientation: "vertical" size: root.width, root.height padding:10 spacing:10 Label: text: "Name" font_size: 45 background_color: (182/255, 66/255, 245/255, 1) canvas.before: Color: rgba: self.background_color Rectangle: size: self.size pos: self.pos # Text Properties color: (0,1,0,1) bold: True italic: True outline_color: (0,0,1) outline_width: 10 TextInput: multiline: False Button: text: "Clear" background_color: (1,0,0,1)
nice manual,
how can we change the label color by py code