Different font size in text (Label)

23 views
Skip to first unread message

gorskijoza

unread,
Apr 10, 2020, 6:39:54 AM4/10/20
to Kivy users support
Hi,

I have defined specifics of a label (TestLabel)

<TestLabel@Label>:
    size_hint: None, None
    size: self.texture_size
    font_size: 40
    text_size: 65, 44
    halign: 'left'
    valign: 'bottom'

now I try to use it 

BoxLayout:
                    size_hint: .45, 1
                    padding: 10 , 15, 10, 0
                    TestLabel:
                        id: test_value_label
                        size_hint: .7, 1
                        text: str(root.test_value) if root.test_value != -1 else ''
                        color: [1,.5,.5,1] if root.test_value > 10 else [1,1,1,1]
 
As text I want to use value and percent sign where value and sign do not have the same font size (as example value (font size 40), percent sign (font size 25)). Is that possible?          

Thank you for your answer in advance.

Joss 

Elliot Garbus

unread,
Apr 10, 2020, 11:08:49 AM4/10/20
to kivy-...@googlegroups.com

Set markup to True in the label, and use markup text

Read: https://kivy.org/doc/stable/api-kivy.uix.label.html?highlight=label#markup-text

 

Example:

 

from kivy.app import App
from kivy.lang import Builder

kv =
"""
BoxLayout:
    Label:
        markup: True
        text: '[size=60]Big Text[/size][size=12]  Small Text[/size]'

"""


class MarkupLabelApp(App):
   
def build(self):
       
return Builder.load_string(kv)


MarkupLabelApp().run()

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/c17f7cc7-ccfe-4e72-bf38-c32edd232db6%40googlegroups.com.

 

Reply all
Reply to author
Forward
0 new messages