0
我正在嘗試使用垂直BoxLayout動態地構建Kivy佈局,其中包含可在運行時更改的自定義小部件MyRow
。 每一行都是一個水平的BoxLayoutKivy嵌套BoxLayout堆棧左下角的小部件
MyRow
佈局正在開發,可以在不久的將來將小工具等等類似這樣的例子
![layout example 2](https://i.stack.imgur.com/x6JRU.png)
但隨着更改代碼
下面我只會看到窗口左下角堆疊在一起的小部件。
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty
class MyRow(Widget):
a = StringProperty('a')
b = StringProperty('b')
def __init__(self, **kwargs):
super(MyRow, self).__init__(**kwargs)
class MainScreen(Widget):
rows = [['a1','b1'],['a2','b2']] #example data
mainLayout = BoxLayout(orientation='vertical', spacing=5)
def __init__(self, **kwargs):
super(MainScreen, self).__init__(**kwargs)
self.add_widget(self.mainLayout)
for r in self.rows:
row_widget = MyRow()
row_widget.a = r[0]
row_widget.b = r[1]
self.mainLayout.add_widget(row_widget)
class MyApp(App):
def build(self):
return MainScreen()
if __name__ == '__main__':
MyApp().run()
,這是千伏文件:
<MyRow>
BoxLayout:
orientation: "horizontal"
spacing: 30
Label:
id: a_label
text: root.a
Label:
id: b_label
text: root.b
Python中使用
class Row(BoxLayout):
繼承這個回答你的問題?如果考慮接受,或者它只是幫助了你,你可能會考慮採取行動。 – PalimPalim