Python | RecycleView in Kivy

Kivy is a platform-independent GUI tool in Python. As it can be run on Android, IOS, Linux and Windows, etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktop applications.

RecycleView:
Recycleview helps to deal with a large number of data items. Recycleview provides the user with the flexibility to scroll down or scroll-up the data displayed in the kivy application. You can also select multiple data items at once. Recycleview is memory efficient as compared to Listview.

To use RecycleView you have to first import it.



from kivy.uix.recycleview import RecycleView

Implementation

filter_none

edit
close

play_arrow

link
brightness_4
code

# Program to explain how to use recycleview in kivy
  
# import the kivy module
from kivy.app import App
  
# The ScrollView widget provides a scrollable view 
from kivy.uix.recycleview import RecycleView
  
  
# Define the Recycleview class which is created in .kv file
class ExampleViewer(RecycleView):
    def __init__(self, **kwargs):
        super(ExampleViewer, self).__init__(**kwargs)
        self.data = [{'text': str(x)} for x in range(20)]
  
# Create the App class with name of your app.
class SampleApp(App):
    def build(self):
        return ExampleViewer()
  
# run the App
SampleApp().run()

chevron_right


The .kv file for the above code

filter_none

edit
close

play_arrow

link
brightness_4
code

<ExampleViewer>:
    viewclass: 'Button'  # defines the viewtype for the data items.
    orientation: "vertical"
    spacing: 40
    padding:10, 10
    space_x: self.size[0]/3
  
    RecycleBoxLayout:
        color:(0, 0.7, 0.4, 0.8)
        default_size: None, dp(56)
  
        # defines the size of the widget in reference to width and height
        default_size_hint: 0.4, None 
        size_hint_y: None
        height: self.minimum_height
        orientation: 'vertical' # defines the orientation of data items

chevron_right


Output:

Above code generates a list of numbers in the range 0 to 20 which can be viewed by scrolling up and down.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.