Change language

Python | Progressbar widget in kiw using .kv file

| |

Kivy — it is a platform independent GUI tool in Python. Since it can run on Android, IOS, Linux, Windows, etc. It is mainly used to develop Android application, but that does not mean that it cannot be used in desktop applications.

Progressbar widget:

The ProgressBar widget is used to visualize the progress of a task. Currently only horizontal mode is supported: vertical mode is not yet available. The progress bar has no interactive elements and is a display-only widget.

To work with the progressbar widget you must have to import it by the command:

from kivy.uix .progressbar import ProgressBar

The progress bar takes two arguments:
1) max: the maximum value allowed. This is a numeric property and the default is 100.
2) value: current value for the slider

 Basic Approach: 1) import kivy 2) import kivyApp 3) import progressbar 4) import Boxlayout (according to need ) 5) Set minimum version (optional) 6) Create Layout class: 7) Create App class 8) Create .kv file: 1) Add progress bar 2) Add label 3) Add canvas if you want as i did 8) return Layout / widget / Class (according to requirement) 9) Run an instance of the class 

Implementation of the approach:

.py file

 

# Program to show how to create a Progressbar in a .kv file

 
# import cool module

import kivy 

 
# Your application base class inherits from the application class.
# app: always refers to your application instance

from kivy.app import App 

 
# this limits the kivy version ie
# below this version you cannot
# use the application or software

kivy.require ( ’1.9.0’

 
# The Label widget is used to render text.

from kivy.uix.label import Label 

  
# The ProgressBar widget is used to
# to visualize the progress or tasks

from kivy.uix.progressbar import ProgressBar 

 
# BoxLayout puts kids in a vertical or horizontal border.
# or help put kids in the right place.

from kivy.uix.boxlayout import BoxLayout

 

 
# A class whose inner workings are in the kv file

class Prog Bar (BoxLayout):

pass

 
# Create application class

class mainApp (App):

def build ( self ):

return ProgBar ()

 
# Create run

if __ name__ = = ’__main__’ :

mainApp (). run ()

.kv file

# .kv file

 
# Extending the ProgBar class in the .kv file
"ProgBar & gt ;:

 

orientation: ’vertical’

  # Create app background

  canvas:

  Color:

rgb:. 45 ,. 28 ,. 5

Rectangle:

pos: self . pos

size: self . size

  

# Provide a label for the pg panel

Label:

text: ’[size = 40px] Progress Bar 1 (at .25)’

color:. 5 , 0 ,. 5 , 1

  markup: True

  

# Create a JPG bar of a specific value

ProgressBar:

value:. 25

min : 0

max : 1

pos_hint: { ’x’ :. 1 }

size_hint_x:. 8

  

  # Provide a label for the pg panel

Label:

text: ’[size = 40px] Progress Bar 2 (at .55) ’

  color:. 5 , 0 ,. 5 , 1

markup: True

  

  # Create a JPG bar of a specific value

ProgressBar:

value:. 55

min : 0

max : 1

  pos_hint: { ’x’ :. 1 }

size_hint_x:. 8

  

Exit:

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically