Label or MDLabel oto-fontsize?

194 views
Skip to first unread message

berk berk

unread,
May 6, 2022, 3:46:30 PM5/6/22
to Kivy users support
I guess Label or MDLabel not have automatic font size for label text size.
when used self.size or root.size crops text. it's does not make a smaller font size.

If that we create a own automatic font size

[This is just question]

Elliot Garbus

unread,
May 7, 2022, 11:29:12 AM5/7/22
to kivy-...@googlegroups.com

Here is an example that scales the font size.  Change the size of the window to see the font size scale to fit.

 

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.button import Button

kv =
"""
<ScaleButton>:
    padding: 20,20

BoxLayout:
    orientation: 'vertical'
    ScaleButton:
        text: 'Test One'
    ScaleButton:
        text: 'This is a test of a longer string of text'
    ScaleButton:
        text: 'Yet another string'
"""


class ScaleButton(Button):
   
def on_size(self, *args):
       
print('on_size')
        t_width,t_height=
self.texture_size
        width,height =
self.size
        loop =
0
       
if t_height < height and t_width < width: # Grow
           
while t_height < height and t_width < width:
               
self.font_size += 1
               
self.texture_update()
                t_width,t_height=
self.texture_size
               
print(f' up {loop}')
                loop +=
1
       
elif t_height > height or t_width > width: # shrink
           
while t_height > height  or t_width > width:
               
self.font_size -= 1
               
self.texture_update()
                t_width,t_height=
self.texture_size
               
print(f' down {loop}')
                loop +=
1


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


ScaleFontApp().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/880064ee-3521-4ee9-89d8-63028ee2f1b3n%40googlegroups.com.

 

berk berk

unread,
May 7, 2022, 7:01:29 PM5/7/22
to Kivy users support
Thanks ElliotG i created oto-font size. Just i wondered that is there any specific code about it. 
7 Mayıs 2022 Cumartesi tarihinde saat 18:29:12 UTC+3 itibarıyla ElliotG şunları yazdı:
Reply all
Reply to author
Forward
0 new messages