Font Size
Date: February 24th 2016
Last updated: February 24th 2016
The default font size is 12 pixels. You can change the font size by specifying it directly using sp (A). Or you can add a root-level button size that can be called by any element (B).
main.py
import kivy
kivy.require('1.9.0')
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
class Sample(BoxLayout):
pass
class SampleApp(App):
def build(self):
# return the boxlayout class defined above
return Sample()
if __name__ == '__main__':
SampleApp().run()
sample.kv
#:kivy 1.9.0
<Sample>:
orientation: 'vertical'
button_font_size: '30sp' #<======= (B) root-level attribute
Label:
text: 'Guess N sampling game!'
size_hint: 1, None
height: self.texture_size[1]
font_size: '45sp' #<========= (A) direct assignment
Label:
text: 'Game info to go here...'
size_hint: 1, 1
TextInput:
text: 'Guess N...'
BoxLayout:
orientation: 'horizontal'
size_hint: 1, None
Button:
text: 'Clear'
size_hint: None, None
font_size: root.button_font_size #<=== (B)
Button:
text: 'Guess!'
size_hint: 1, None
font_size: root.button_font_size #<=== (B)
Button:
text: 'Quit'
size_hint: None, None
font_size: root.button_font_size #<=== (B)
Output
Note that I have changed the boxlayout from previous examples.