我在 python 脚本中有这段代码,它工作得很好。我一直在尝试将其转换为 KV,以便将其包含在我的应用程序中,但我的尝试失败了。请帮助 :( 转换所需的代码如下,它已在 python 3.4.4 中编码。目前它被编程为应用程序,但我需要它作为屏幕:
if __name__ == '__main__':
from kivy.app import App
from kivy.uix.scrollview import ScrollView
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
class ScrollViewApp(App):
def build(self):
layout1 = GridLayout(cols=6, spacing=10, size_hint=(None, None))
layout1.bind(minimum_height=layout1.setter('height'),
minimum_width=layout1.setter('width'))
for i in range(200):
btn = Button(text='student'+str(i), size_hint=(None, None),
size=(200, 100))
layout1.add_widget(btn)
scrollview1 = ScrollView(bar_width='10dp')
scrollview1.add_widget(layout1)
root = GridLayout(cols=1)
root.add_widget(scrollview1)
return root
ScrollViewApp().run()