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.