Skip to content

Instantly share code, notes, and snippets.

@kived
Created July 30, 2015 21:40
Show Gist options
  • Save kived/7c212cf2d95b305bb193 to your computer and use it in GitHub Desktop.
Save kived/7c212cf2d95b305bb193 to your computer and use it in GitHub Desktop.
Kivy: markup label color test
import kivy
kivy.require('1.9.0')
from kivy.app import App
from kivy.lang import Builder
from kivy.factory import Factory
from kivy.clock import Clock
root = Builder.load_string('''
FloatLayout:
canvas.before:
Color:
rgba: 1, 1, 1, 1
Rectangle:
size: self.size
<TestLabel@Label>:
font_size: 18
size_hint_y: None
text_size: self.width, None
height: self.texture_size[1]
halign: 'left'
markup: True
color: 0, 0, 0, 1
''')
class TestApp(App):
def build(self):
self.lbl = Factory.TestLabel(text='te[color=ff0000]st[/color]ing')
root.add_widget(self.lbl)
Clock.schedule_interval(self.update_label, 1)
return root
def update_label(self, dt):
self.lbl.color = (0, 1, 0, 1) if self.lbl.color[1] == 0 else (0, 0, 0, 1)
if __name__ == '__main__':
TestApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment