Resizing Heights

Date: February 24th 2016
Last updated: February 24th 2016

You can collapsing a container using texture_size[1]. Texture_size reduces the height of a container to the height of an element or object such as text.

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'
    Label:
        text: 'Guess N sampling game!'
        size_hint: 1, None
        height: self.texture_size[1] #<===== adjust height
    TextInput:
        text: 'Guess N...'
    BoxLayout:
        orientation: 'horizontal'
        size_hint: 1, None
        Button:
            text: 'Guess!'
            size_hint: 1, None
        Button:
            text: 'Clear'
            size_hint: None, None
        Button:
            text: 'Quit'
            size_hint: None, None

Output

texture_size boxlayout screenshot

results matching ""

    No results matching ""