Padding
Date: February 24th 2016
Last updated: February 24th 2016
padding can be added to move objects away from the edge of the element container.
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'
padding: root.width * 0.02, root.height * 0.02 #<=== 2% padding
Label:
text: 'Guess N sampling game!'
size_hint: 1, None
height: self.texture_size[1]
font_size: '45sp'
Label:
text: 'Game info to go here...'
size_hint: 1, 1
TextInput:
text: 'Guess N...'
padding: root.width *0.05, root.height * 0.05 # <=== 5% padding
BoxLayout:
orientation: 'horizontal'
size_hint: 1, None
Button:
text: 'Clear'
size_hint: None, None
font_size: root.button_font_size
Button:
text: 'Guess!'
size_hint: 1, None
font_size: root.button_font_size
Button:
text: 'Quit'
size_hint: None, None
font_size: root.button_font_size
Output
Note the addition of spacing around the edge of the boxlayout. Also notice that this didn't add spacing between buttons or other elements.