蟒蛇文件:
import kivy
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.stacklayout import StackLayout
from kivy.uix.gridlayout import GridLayout
from kivy.metrics import dp
from kivy.core.audio import SoundLoader
class AppLayout(BoxLayout):
def __init__(self,**kwargs):
super().__init__(**kwargs)
for i in range(0,10):
size = dp(100)
b = Button(text=str(i+1), size_hint=(None,None), size=(size,size))
self.add_widget(b) #Adds buttons in
# It makes buttons but complete outside the kv file, both this
# and the kv file are all mushed together if that makes sense.
class SoundApp(App):
pass
if __name__ == "__main__":
SoundApp().run()
基维文件:
AppLayout:
<AppLayout>:
BoxLayout:
cols: 1
orientation: "vertical"
Label:
text: "Song title"
ScrollView:
# I want to create multiple boxes
# in this scroll view layout
id: scroll_view
cols:1
orientation: "vertical"
BoxLayout:
cols:3
rows: 1
orientation: "horizontal"
spacing: 10
padding: 5
Button:
text: "Shuffle"
size_hint: 0.2,0.2
Button:
text: "Delete"
size_hint: 0.2,0.2
Button:
text: "Add"
size_hint: 0.2,0.2
总而言之,我不知道如何ScrollView
专门创建或迭代布局中的按钮。当我运行它时,它会变得杂乱无章。我怎么能把python代码中的迭代按钮放在ScrollView
布局中?