Skip to content
Related Articles

Related Articles

Improve Article

Python | RecycleView in Kivy

  • Last Updated : 30 Jan, 2020

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 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


# Program to explain how to use recycleview in kivy
# import the kivy module
from 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) = [{'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

The .kv file for the above code

    viewclass: 'Button'  # defines the viewtype for the data items.
    orientation: "vertical"
    spacing: 40
    padding:10, 10
    space_x: self.size[0]/3
        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


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

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :