Table of contents
1.
Introduction
2.
Progress Bar Widget
2.1.
Uses of the Progress Bar
2.2.
Syntax
3.
Implementation in Python
3.1.
Explanation
3.2.
Output 1(Before Start Button is Pressed)
3.3.
Output 2(After Start Button is Pressed)
4.
Frequently Asked Questions
4.1.
What can Kivy do?
4.2.
Is it simple to use Kivy?
4.3.
Is it worthwhile to learn Kivy?
4.4.
Is Kivy native?
5.
Conclusion
Last Updated: Mar 27, 2024

Progress Bar Widget in Kivy

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

If you are new to kivy, we recommend you go through our articles on ‘Window Size Adjustment in Kivy’ and ‘Box Layout in Kivy’ to understand the basics of the kivy toolkit in Python.

Have you ever seen an animated wheel or a progress bar showing the status of a task in an application? In Kivy, we can accomplish this by using the progress bar widget. 

In this article, we'll look at various characteristics of the Kivy progress bar widget and how to implement it in Python.

So let's get started; I hope you will enjoy learning about the Kivy progress bar widget.

Progress Bar Widget

The Progress Bar is a great way to visualise the passage of time. Most applications visualise the progress of some ongoing task using a progress bar.

In kivy, we are already provided with a customisable progress bar widget to show progress. At this time, only the horizontal mode is supported; the vertical mode is not available. The progress bar is a display-only widget with no interactive elements.

Uses of the Progress Bar

One of the most significant graphical control elements is the progress bar, which monitors the progress of various processes in an application.
We may use a progress bar to visualise the progress in the following cases:

  • Progress on downloading
  • Installing the app
  • Saving updates
  • File Transfer
  • Loading an activity into an application

Syntax

The progress bar widget can be imported using the kivy.uix package. The basic syntax of dealing with a Kivy progress bar is as follows.

from kivy.uix.progressbar import ProgressBar
pbar = ProgressBar(max=100, value=50)
You can also try this code with Online Python Compiler
Run Code

There are two arguments for the progress bar:

  1. max: The maximum value that can be assigned to the progress bar. It's a numeric property with a value of 100 by default.
  2. value: The current value of the slider

Implementation in Python

In the below example, we have implemented a program to demonstrate the progress bar widget to show the progress of some tasks in an application.

#program for progress bar in kivy
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock
from kivy.uix.widget import Widget
from time import sleep
from kivy.uix.progressbar import ProgressBar

#class for progress bar
class MyApp(App):
    def build(self):
        self.progress = ProgressBar(max=100)
        self.progress.value = 0
        
        #button for start and stop
        self.button = Button(text='Start', size_hint=(.2, .1))
        self.button.bind(on_press=self.start)
        self.layout = BoxLayout(orientation='vertical')
        self.layout.add_widget(self.progress)
        self.layout.add_widget(self.button)
        return self.layout
        
    #function for start and stop
    def start(self, instance):
        self.button.disabled = True
        self.button.text = 'In Progress!'
        self.button.bind(on_press=self.stop)
        self.progress.value = 0
        Clock.schedule_interval(self.update, 0.1)
        
    #function for update
    def update(self, dt):
        self.progress.value += 1
        if self.progress.value == 100:
            self.button.disabled = False
            self.button.text = 'Start'
            self.button.bind(on_press=self.start)
            Clock.unschedule(self.update)
if __name__ == '__main__':
    MyApp().run()
You can also try this code with Online Python Compiler
Run Code

Explanation

In this approach, we have imported the Kivy library. Then we imported the kivyApp and progress bar packages and the BoxLayout module to display the progress bar according to the requirements. Then we created the App class and called it from the main function. Additionally, we have defined the start and update functions for the functionality of the progress bar.

Output 1(Before Start Button is Pressed)

We can notice the default value of the progress bar is set to "0." Thus, we can see no progress until we press the start button.

Output 2(After Start Button is Pressed)

Here, the progress bar has reached almost 35% of the total width, and the button is inactive. The button now displays the text “In Progress!” as defined in the start method.

Frequently Asked Questions

What can Kivy do?

Kivy is a Python package that allows you to construct mobile and desktop applications using Python. It takes your code and turns it into apps based on your logic. Then it delivers an almost complete Python installation with each app.
 

Is it simple to use Kivy?

The widgets that come pre-installed with the Kivy platform are simple and support multi-touch. The Kivy framework outperforms other HTML5 options because the GUI is simple and aids in the speedy development of applications.
 

Is it worthwhile to learn Kivy?

It is worthwhile to learn. It can help you create apps faster; if you're making mobile apps, all you need is one code to target all platforms (android and iOS), and it's easier to use than Android Studio (I'm not sure about iOS and Xcode).
 

Is Kivy native?

When you use Kivy to make an application, you're making a Natural User Interface, or NUI. The goal of a natural user interface is for the user to learn how to use your product with little to no guidance. Kivy does not attempt to leverage native widgets or controls. Its widgets are all hand-drawn.

Conclusion

In this article, we have discussed the Kivy Progress Bar widget and its parameters. We learned about the Progress Bar widget's uses, syntax, and implementation in Python.

We hope that this blog has helped you enhance your knowledge on how to adjust window size in Kivy using Python, and if you would like to learn more, check out our articles on the "Button action in kivy," "Scroll View Widget in Kivy," "Button colour in kivy," "Dropdown list in Kivy," and "Kivy float layout.’ Do upvote our blog to help other ninjas grow.

Head over to our practice platform Coding Ninjas Studio to practice top problems, attempt mock tests, read interview experiences, interview bundle, follow guided paths for placement preparations and much more!

Happy Reading!

Live masterclass