pythonkivy

How to create listbox in kivy python?


I'm writing a file manager in kivy. How can I add listbox into kivy app?
And How can I bind functions to double-click.


Solution

  • IMO, you could make your 'listbox' using a RecycleView with Labels or BoxLayouts.

    Something like:

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

    Then somewhere in your .py file:

    ...
    dat = []
    for l in ["label1", "label2"," label3"]:
        dat.insert(0,{'text':l,'color': (1,1,0,1)}
    
    self.ids.rv.data = dat
        
    

    Note that, the viewclass defines what will be the contents of your RecycleView , as such, this should be a valid Kivy class which in this case is just a list of Labels. For something more complicated, you can create your own widgets