简体   繁体   中英

RecyleView with .kv file (Python/Kivy)

Total python newbie question here. Trying to implement a basic RecycleView here but it is not showing up when I run it. I don't get any errors (outside of a warning stating that I am loading the my.kv file multiple times....I will fix that next)

Any tips on how to get it to run??

I only included code snippets of what is currently being used to try and implement the view.

.py code

from kivy.app import App
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.lang import Builder



class TransactionScreen(Screen):
    def __init__(self, **kwargs):
        super(TransactionScreen, self).__init__(**kwargs)
        self.data = [{'text': str(x)} for x in range(100)]


class WindowManager(ScreenManager):
    pass


kv = Builder.load_file("my.kv")


class MyApp(App):
    def build(self):
       return kv


if __name__ == '__main__':
    MyApp().run()

.ky code

    TransactionScreen:



<TransactionScreen>:
    name:"transactions"

    viewclass:'Label'
    RecycleBoxLayout:
        default_size:None, dp(56)
        default_size_hint:1, None
        size_hint_y:None
        height:self.minimum_height
        orientation:'vertical'



You do not have a RecycleView in your code. One quick fix is to change:

class TransactionScreen(Screen):

to:

class TransactionScreen(RecycleView):

or, perhaps a better approach is to just add a RecycleView to the TransactionScreen :

<TransactionScreen>:
    name:"transactions"

    RecycleView:
        viewclass:'Label'
        data: root.data
        RecycleBoxLayout:
            default_size:None, dp(56)
            default_size_hint:1, None
            size_hint_y:None
            height:self.minimum_height
            orientation:'vertical'

and leave the TransactionScreen as:

class TransactionScreen(Screen):

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM