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
from kivy.app import App
from kivy.uix.recycleview import RecycleView
class ExampleViewer(RecycleView):
def __init__( self , * * kwargs):
super (ExampleViewer, self ).__init__( * * kwargs)
self .data = [{ 'text' : str (x)} for x in range ( 20 )]
class SampleApp(App):
def build( self ):
return ExampleViewer()
SampleApp().run()
|
The .kv file for the above code
<ExampleViewer>:
viewclass: 'Button'
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 )
default_size_hint: 0.4 , None
size_hint_y: None
height: self .minimum_height
orientation: 'vertical'
|
Output:
Above code generates a list of numbers in the range 0 to 20 which can be viewed by scrolling up and down.
Last Updated :
30 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...