Skip to content

Instantly share code, notes, and snippets.

@Alan-FGR
Created July 30, 2015 17:45
Show Gist options
  • Save Alan-FGR/264b9d1ea3a747f8fd92 to your computer and use it in GitHub Desktop.
Save Alan-FGR/264b9d1ea3a747f8fd92 to your computer and use it in GitHub Desktop.
__author__ = 'Alan'
__version__ = '0.1'
import kivy
kivy.require("1.0.0")
from kivy.app import Builder
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.scrollview import ScrollView
mybutstr = """
Button:
text_size: self.width-dp(20), None
size_hint_y: None
height: self.texture_size[1]+dp(20)
"""
class MyApp(App):
def build(self, **kwargs):
scr = ScrollView()
mainlo = GridLayout(cols = 2, size_hint_y = None)
mainlo.bind(minimum_height = mainlo.setter("height"))
scr.add_widget(mainlo)
leftlo = GridLayout(cols=1, size_hint_y = None)
leftlo.bind(minimum_height = leftlo.setter("height"))
mainlo.add_widget(leftlo)
rightlo = GridLayout(cols=1, size_hint_y = None)
mainlo.add_widget(rightlo)
for i in range(20):
newb = Builder.load_string(mybutstr)
newb.text = (str(i)+' ')*(1+i*2)
leftlo.add_widget(newb)
return scr
MyApp().run()
@Alan-FGR
Copy link
Author

Fix (thanks to Kived):

__author__ = 'Alan'
__version__ = '0.1'

import kivy
kivy.require("1.0.0")

from kivy.app import Builder
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.scrollview import ScrollView

from kivy.uix.stacklayout import StackLayout

mybutstr = """
Button:
    text_size: self.width-dp(20), None
    size_hint_y: None
    height: self.texture_size[1]+dp(20)
"""

class MyApp(App):
    def build(self, **kwargs):

        scr = ScrollView()

        mainlo = StackLayout(orientation = 'lr-tb', size_hint_y = None)
        mainlo.bind(minimum_height = mainlo.setter("height"))
        scr.add_widget(mainlo)

        leftlo = GridLayout(cols=1, size_hint_y = None, size_hint_x=.5)
        leftlo.bind(minimum_height = leftlo.setter("height"))
        mainlo.add_widget(leftlo)

        rightlo = GridLayout(cols=1, size_hint_y = None,  size_hint_x=.5)
        rightlo.bind(minimum_height = rightlo.setter("height"))
        mainlo.add_widget(rightlo)

        for i in range(20):
            newb = Builder.load_string(mybutstr)
            newb.text = (str(i)+' ')*(1+i*2)
            leftlo.add_widget(newb)

        return scr

MyApp().run()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment