Table of contents
1.
Introduction
2.
Basic Approach
3.
Example
4.
Frequently Asked Questions
4.1.
How do we make a progressBar widget?
4.2.
What is a widget in kivy?
4.3.
What are Layouts?
4.4.
How do we create a dropdown list in kivy?
4.5.
How to create progressBar in python?
5.
Conclusion
Last Updated: Mar 27, 2024
Easy

Progress Bar widget using .kv file

Author yuvatimankar
1 upvote

Introduction

Kivy is a GUI tool that is platform-independent in Python. Kivy can be run on android, IOS, Linux, windows, etc. It is used to create the Android application, but this does not mean that we cannot use it on desktop applications. 

ProgressBar widget is used to picture the progress of some tasks. The only horizontal mode is currently supported; the vertical mode is not available yet. It is a display-only widget, and it has no interactive element.

To work with progressBar widget we have to import command:

from kivy.uix.progressBar import ProgressBar
You can also try this code with Online Python Compiler
Run Code

 

Progressbarwidget takes two arguments: Max & Value.

Max: It is a maximum value allowed for value. It is a numeric property and defaults to 100.

Value: It is a current value for the slider.

Basic Approach

  • import kivy
  • import kivy app
  • import progress bar
  • see minimum version(if needed)
  • Create Layout class
  • Create app class
  • Create .kv file - Add progress bar, add label, add canvas (optional)
  • Return layout/widget/class
  • Run an instance of the class

Example

1..py file

import kivy 
from kivy.app import App
kivy.require('1.9.0') 
from kivy.uix.label import Label 
from kivy.uix.progressbar import ProgressBar
from kivy.uix.boxlayout import BoxLayout

class ProgBar(BoxLayout)
 pass

# Create the App Class   
class mainApp(App):
    def build(self):
        return ProgBar()


if __name__=='__main__':
    mainApp().run()
You can also try this code with Online Python Compiler
Run Code

 

2. .kv file

<ProgBar>:
  
    orientation: 'vertical'
    # Creating the background of the App
    canvas:
        Color:
            rgb: .45, .28, .5
        Rectangle:
            pos: self.pos
            size: self.size
  
    # Providing label to the pg bar
    Label:
        text: '[size = 40px]Progress Bar 1 (at .25)'
        color: .5, 0, .5, 1
        markup: True
  
    # Creating the pg bar of specific value
    ProgressBar:
        value: .25
        min: 0
        max: 1
        pos_hint: {'x':.1}
        size_hint_x: .8
  
    # Providing label to the pg bar
    Label:
        text: '[size = 40px]Progress Bar 2 (at .55)'
        color: 
rgb: 176, 97, 140
        markup: True
  
    # Creating thepg bar of specific value
    ProgressBar:
        value: .55
        min: 0
        max: 1
        pos_hint: {'x':.1}
        size_hint_x: .8
You can also try this code with Online Python Compiler
Run Code

Output:

2. 

import kivy  
from kivy.app import App  
from kivy.uix.widget import Widget  
from kivy.uix.button import Button  
from kivy.uix.progressbar import ProgressBar  
from kivy.uix.boxlayout import BoxLayout  
from kivy.clock import Clock  
from time import sleep  
   
class MainMenu(BoxLayout):  
    def __init__(self):  
        super().__init__()  
        self.orientation = 'vertical'  
         
        btn = Button(text="Start")  
        btn.bind(on_release=self.trigger)  
        self.add_widget(btn)  
         
        self.MyList = ('My', 'first', 'Progress', 'Bar')  
        self.i = 0  
        self.pb = ProgressBar(max = len(self.MyList), value = 0)      
        self.add_widget(self.pb)  
                 
    def trigger(self, *args):  
      self.i = 0  
      self.pb.value = 0  
       
      Clock.schedule_interval(self.heavyFunc,0.1)  
     
    def heavyFunc(self, dt):  
        sleep(0.5)  
        print(self.MyList[self.i])  
        self.i += 1  
        self.pb.value +=1  
        if self.i >= len(self.MyList):  
            Clock.unschedule(self.heavyFunc)  
            print('unscheduled')  
   
class TestApp(App):  
    def build(self):  
        return MainMenu()  
   
root = TestApp()  
root.run()  
You can also try this code with Online Python Compiler
Run Code

Output:

Frequently Asked Questions

How do we make a progressBar widget?

In the .kv file, we have to add a progressBar and add the elements which are to be shown.

What is a widget in kivy?

A Widget is the base building block of GUI interfaces in Kivy. It provides a Canvas that can be used to draw on the screen. It receives events and reacts to them.

What are Layouts?

Layouts are containers used to organize widgets in a particular manner.

How do we create a dropdown list in kivy?

Firstly import the kivy, 2. Import kivy app 3. Then, we will import the dropdown list. 4. Import the button 5. Import the runTouchApp and then at last we will create a dropdown.

How to create progressBar in python?

1. install the tqdm package 

2. write the python code 

3. create the progressBar in python 

4. Add a GUI to track your progress(optional) 5. 

Conclusion

In this article, we have extensively discussed the progress bar using kivy python; also, we have seen some examples of the progress bar in which we have created the progressBar widget using .kv and the main file. 

After reading about this topic, are you not feeling excited to read/explore more articles on the topics of kivy python? Don’t worry, Coding ninjas has you covered. To learn more on such topics, you can visit StackLayout in Kivy using .kv file, FloatLayout in Kivy using .kv file, BoxLayout Widget in Kivy, The drop-down List In Kivy, and Background template in Kivy!

Refer to our guided path on Coding Ninjas Studio to upskill yourself in Data structure and algorithmsCompetitive Programming, JavascriptSystem Design, and many more if you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio But if you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc. you must look at the problemsinterview experiences, and interview bundle for placement preparations.

Nevertheless, you may consider our paid courses to give your career an edge over others.

Do upvote our blogs if you find them helpful and engaging!

Happy coding!

Live masterclass