In this video I’ll show you how to create and use Progress Bars with Kivy and Python.

Progress bars are a great way to visualize the passage of time or anything else in your Kivy app. Creating a progress bar is super easy, you just call it in your .kv file, give it a min and max, and set a default value for whatever position you’d like it to start on.

That’s really all there is to it. To update it you can just reference the id of the ProgressBar on your back end and increment it whenever you like!

In this video I’ll show you how to increment the progress bar 25% every time a user clicks a button.

Python Code: progress.py
GitHub Code: progress.py

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.lang import Builder

# Designate Our .kv design file 
Builder.load_file('progress.kv')

class MyLayout(Widget):
	def press_it(self):
		# Grab the current progress bar value
		current = self.ids.my_progress_bar.value
		# If statement to start over after 100
		if current == 1:
			current = 0

		# Increment value by .25
		current += .25
		# Update the progress bar
		self.ids.my_progress_bar.value = current
		# Update the label
		self.ids.my_label.text = f'{int(current*100)}% Progress'

class AwesomeApp(App):
	def build(self):
		return MyLayout()


if __name__ == '__main__':
	AwesomeApp().run()




Kivy Design Code: progress.kv
GitHub Code: progress.kv

<MyLayout>
	BoxLayout:
		orientation: "vertical"
		size: root.width, root.height
		
		Label:
			id: my_label
			text: "0% Progress"

		ProgressBar:
			id: my_progress_bar
			# Set Default Value
			# value: .25
			min: 0
			max: 1
			pos_hint: {'x':.1}
			size_hint_x: .8

		Button:
			text: "Press Me!"
			on_press: root.press_it()

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of the first dot com boom. After that he developed the award-winning Submission-Spider search engine submission software that's been used by over 3 million individuals, businesses, and governments in over 42 countries. He's written several Amazon #1 best selling books on coding, and runs a popular Youtube coding channel.

View all posts

Add comment

Your email address will not be published. Required fields are marked *

John Elder