from kivy.uix.gridlayout import GridLayout
from kivy.app import App
from kivy.lang.builder import Builder
from kivy.uix.scrollview import ScrollView
from kivy.uix.button import Button Builder.load_string('''
<G>
spacing: '10dp'
cols: 1
size_hint_y: None
B: <B>
text: ''
size_hint_y: None
height: '40dp'
on_release: self.parent.click(self) <S>
size_hint: 1, None
size: ('400dp', '600dp')
G:
''') class G(GridLayout):
def click(self, instance):
self.bind(minimum_height = self.setter('height'))
for i in range(100):
a = B()
a.text = str(i)
self.add_widget(a) class B(Button):
pass class S(ScrollView):
pass class MyApp(App):
def build(self):
return S() if __name__ == '__main__':
MyApp().run()
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.scrollview import ScrollView
from kivy.core.window import Window
from kivy.app import runTouchApp layout = GridLayout(cols=1, spacing=10, size_hint_y=None)
# Make sure the height is such that there is something to scroll.
layout.bind(minimum_height=layout.setter('height')) #******必须指定..................
print(layout.setter('height'))
for i in range(100):
btn = Button(text=str(i), size_hint_y=None, height=40)
layout.add_widget(btn)
root = ScrollView(size_hint=(1, None), size=(Window.width, Window.height))
root.add_widget(layout) runTouchApp(root)