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
# 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() |
The .kv file for the above 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 |
Output:
Above code generates a list of numbers in the range 0 to 20 which can be viewed by scrolling up and down.
<!–
–>
Please Login to comment…