新成员,第一个职位。我会尽量具体和清楚。下面的代码来自kivy关于RecycleView module 的网页。我想使用这段代码,但是,我不希望使用KV lang和Builder,而是用纯python3编写代码。我试图将RecycleBoxLayout类添加为小部件,但完全失败了,结果只是一个黑色窗口。只有添加了“viewclass”才起作用。很明显,这里有些东西我不明白或者遗漏了。我还附上了我重写代码的尝试。在
任何帮助都将不胜感激。提前谢谢你。在
原始代码:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.recycleview import RecycleView
Builder.load_string('''
<RV>:
viewclass: 'Label'
RecycleBoxLayout:
default_size: None, dp(56)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
''')
class RV(RecycleView):
def __init__(self, **kwargs):
super(RV, self).__init__(**kwargs)
self.data = [{'text': str(x)} for x in range(100)]
class TestApp(App):
def build(self):
return RV()
if __name__ == '__main__':
TestApp().run()
我的尝试失败:
^{pr2}$
我也在寻找同样的东西,我不喜欢kv-lang,而且还没有确信它比用代码做任何事情都好。在
来自https://kivy.org/docs/api-kivy.uix.recycleview.html#kivy.uix.recycleview.RecycleView的示例将按如下方式创建。在
KV等级的顺序很重要。不知道什么东西需要放在哪里,但是自我数据需要在添加小部件后进行修改。在
我不是Kivy的专家,但我强烈建议您尽量使用
}和
}参数。在
kv lang
。它只不过是一个简洁的python,它将使您的代码更加简洁。如果您阅读
RecycleBoxLayout
的文档,它是高度实验性的,那么您应该使用有效的方法。也就是说,你的代码看起来不错,但是有几个问题。
1)更换
self.viewclass = Label
与{2)您尚未在python代码中为您的
height
、size
和{相关问题 更多 >
编程相关推荐