New member, first post. I will try to be specific and clear. The following piece of code is taken from kivy's webpage regarding the RecycleView module . I would like to use this piece of code, however, I would prefer not to use the KV lang and the Builder, but write the code in pure Python 3. My attempt to add the RecycleBoxLayout class as a widget was a complete failure as the result is simply a black window. Only the addition of the "viewclass" is working. Obviously, there is something I don't understand or missing here. I have also attached my attempt to rewrite the code.
Any help would be greatly appreciated. Thank you, in advance.
Original Code:
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()
My failed attempt:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.recycleview import RecycleView
from kivy.uix.label import Label
from kivy.uix.recycleboxlayout import RecycleBoxLayout
class RV(RecycleView):
def __init__(self, **kwargs):
super(RV, self).__init__(**kwargs)
self.data = [{'text': str(x)} for x in range(100)]
self.viewclass = Label
layout = RecycleBoxLayout()
self.add_widget(layout)
class TestApp(App):
def build(self):
return RV()
if __name__ == '__main__':
TestApp().run()
I'm not an expert in Kivy but I would highly recommend you to use kv lang
as much as possible. Its nothing more than a concise python and it will make your code much cleaner.
if you read the documentation for RecycleBoxLayout
its highly experimental and you should make use of what works.
That being said, your code looks okay but with a couple of problems.
1) Replace
self.viewclass = Label
with self.viewclass = 'Label'
and
2) You havent specified the height
, size
and orientation
parameters for your RecycleBoxLayout
in your python code.