How to change label colour dynamically?

22 views
Skip to first unread message

ilias iliadis

unread,
Jan 16, 2018, 12:42:35 AM1/16/18
to Kivy users support
Is there a way to change the label colour dynamically, a.k.a. depending on some user interaction with the app? example: every time user presses some button?
(Sorry for the subject. I do not know if it is considered good practice creating new subject with the same name, but the other subject, with the same name, is about "setting the initial colour" -question and answers found there- and not changing it dynamically)
Thanks
ilias

Leonardo Rodriguez

unread,
Jan 16, 2018, 8:13:15 AM1/16/18
to Kivy users support
example:

file.kv
    Label:
       id: clab
       text: "hello there"
      background_color: 0,0,0,1
      color: 1,1,1,1  


in the main.py

...
   self.ids.clab.color = [1,0,0,1]                           #label id referenced
   self.ids.clav.background_color = [0,1,1,1]


You can also change de text color like this

self.ids.clab.markup = True   #this property must be set to true in order to make possible the text of the label to be procesed
self.ids.clab.text = "[color=ff0000]Hello[/color][color=00ff00]World[/color]"

ilias iliadis

unread,
Jan 16, 2018, 10:58:54 PM1/16/18
to Kivy users support
Thanks, is working!
Reply all
Reply to author
Forward
0 new messages