Kivy Text Markup Printing Its Own Syntax
I was testing out Kivy's markup feature. The basic outline of my test program is there are 4 labels and a button and if the button is pressed, it changes the color of the first let
Solution 1:
The markup is part of the string stored in text
. So the second time you run the loop, indeed the first character ([
) gets inserted in between the markup tags, messing up the parsing.
What you want to do could be achieved by storing the raw text in another StringProperty
, let's call it _hidden_text
. Then, in the loop, you can set
self.root.ids[lol].text = '[color=#E5D209]{}[/color]{}'.format(self.root.ids[lol]._hidden_text[0], self.root.ids[lol]._hidden_text[1:])
In this way you avoid reusing the added markup.
Of course you may want to set up bindings for making the assignment _hidden_text
→text
automatic.
Edit:
Add this class definition:
class CLabel(Label):
hidden_text = StringProperty('')
then change the kv style for CLabel
to
<CLabel>:markup:Truetext:self.hidden_text
and each use of CLabel
should look like
CLabel:
id: a
hidden_text: 'abcd'
Post a Comment for "Kivy Text Markup Printing Its Own Syntax"