Open In App
Related Articles

Python | Scrollview widget in kivy

Improve Article
Save Article
Like Article

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.

 Kivy Tutorial – Learn Kivy with Examples.

Scroll view:

The ScrollView widget provides a scrollable/pannable viewport that is clipped at the scrollview’s bounding box. Scroll view accepts only one child and applies a window to it according to 2 properties: 

  1. scroll_x
  2. scroll_y

To determine if the interaction is a scrolling gesture, these properties are used:

  • scroll_distance: the minimum distance to travel, defaults to 20 pixels.
  • scroll_timeout: the maximum time period, defaults to 55 milliseconds.

To use the scrollview you must have to import it:
from kivy.uix.scrollview import ScrollView

Basic Approach:
1) import kivy
2) import kivyApp
3) import scroll view
4) import string property
5) Set minimum version(optional)
6) create the scroll view class
7) Build the .kv file within the .py file
8) Run an app

Implementation of the code:


# Program to explain how to use scroll view in kivy 
# import kivy module    
import kivy  
# base Class of your App inherits from the App class.    
# app:always refers to the instance of your application   
from import App 
# this restrict the kivy version i.e  
# below this kivy version you cannot  
# use the app or software  
# The Label widget is for rendering text
from kivy.uix.label import Label
# The ScrollView widget provides a scrollable view
from kivy.uix.scrollview import ScrollView
# Property that represents a string value
from import StringProperty
# Static main function that starts the application loop.
from kivy.base import runTouchApp
# Builder is a global Kivy instance used in
# widgets that you can use to load other
# kv files in addition to the default ones.
from kivy.lang import Builder
# Build the .kv file
# Define the scroll view
    text: 'You are learning Kivy' * 500
        text: root.text
        font_size: 50
        text_size: self.width, None
        size_hint_y: None
        height: self.texture_size[1]
# Define scrollview class
class ScrollableLabel(ScrollView):
    text = StringProperty('')
# run the App


You can also change color of ScrollBar and its width as shown below code but for that, you have to use properties of ScrollView  like 

  1. bar_color: It requires a list in RGB format for specifying bar color
  2. bar_width: It requires a number for specifying the bar size

Code For Changing Bar Color and Bar width:


from import App
# importing builder from kivy
from kivy.lang import Builder
# this is the main class which will
# render the whole application
class uiApp(App):
    # method which will render our application
    def build(self):
        return Builder.load_string(
            size_hint: (1, 1)
            # here we can set bar color
            bar_color: [0, 0, 255, 1]
            # here we can set bar width
            bar_width: 12
            size: (self.parent.width, self.parent.height-1)
            id: container
            orientation: "vertical"
            size_hint_y: None
            height: self.minimum_height
            rgba:  rgba("#50C878")
            pos: self.pos
            size: self.size
            size_hint: (1, None)
            height: 300
            markup: True
            text: "[size=78]GeeksForGeeks[/size]"
            size_hint: (1, None)
            height: 300
            markup: True
            text: "[size=78]GeeksForGeeks[/size]"
            size_hint: (1, None)
            height: 300
            markup: True
            text: "[size=78]GeeksForGeeks[/size]"
            size_hint: (1, None)
            height: 300
            markup: True
            text: "[size=78]GeeksForGeeks[/size]"
# running the application



Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 15 Sep, 2021
Like Article
Save Article
Similar Reads
Complete Tutorials