我正在尝试建立一个结构,将有多列数据将被更新,并必须滚动在一起。
整个应用程序有多个页面,等等。它的标签构建部分确实可以工作,因为它将"hello world“放在页面的正确部分。但是,它似乎是一个接一个地填充所有数据,即使我使用的是"index“属性。下面是py和kv文件中的一些代码片段:
class RV(FloatLayout):
def re_build(self):
label_list = [Label(text = "Label {}".format(x)) for x in range(20)]
for count, x in enumerate(label_list):
self.add_widget(Label(text='Hello World'), index = count)'
class MainScreen(Screen):
pass
class ScreenManagement(ScreenManager):
pass
class TestApp(App):
def build(self):
return ScreenManagement()
if __name__ == '__main__':
# Here the class MyApp is initialized
# and its run() method called.
TestApp().run() <ScreenManagement>:
padding: 10
MainScreen:
id: main_screen
name: 'main_screen'
<MainScreen>:
GridLayout:
rows:3
cols:1
Button:
size_hint: 1, None
height: 50
text: "just setting up"
on_press:
root.ids.rv.re_build()
RV:
id: rv
GridLayout:
rows:3
cols:2
size_hint : None, None
CheckBox:
active:False
Label:
text: 'item 1'
CheckBox:
active:False
Label:
text: 'item 2'
CheckBox:
active:False
Label:
text: 'item 3'感谢您的任何帮助
发布于 2021-03-20 06:34:21
你的代码:
self.add_widget(Label(text='Hello World'), index = count)正在将Label添加到您的RV类,这是一个FloatLayout。在FloatLayout中,add_widget()调用中的index对Label的位置没有影响,它只影响标签的绘制顺序。尝试使用不同的Layout作为RV类的基类。一些将根据index定位其子对象的示例包括GridLayout、BoxLayout和StackLayout。
https://stackoverflow.com/questions/66716056
复制相似问题