In this video I’ll show you two different ways to change the background color of your app with Kivy and Python.

Changing the background color of your app is a pretty fundamental thing in GUI programming and with Kivy it’s pretty easy. I’ll show you how to do it in your Kivy language file using a Canvas and a Rectangle, and I’ll also show you a second way to do it in your actual python file using kivy.core.window

Python Code: bg.py
GitHub Code: bg.py

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from kivy.lang import Builder
from kivy.core.window import Window

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

class MyLayout(Widget):
	pass
	
class AwesomeApp(App):
	def build(self):
		Window.clearcolor = (1,0,0,1)
		return MyLayout()

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


Kivy Design Code: bg.kv
GitHub Code: bg.kv

<MyLayout>
	canvas.before:
		Color:
			rgba: (0,0,1,1)
		Rectangle:
			pos: self.pos
			size: self.size

	BoxLayout:
		orientation: "vertical"
		size: root.width, root.height
		
		padding: 50
		spacing: 20

		Button:
			text: "Hello World!"
		
		Button:
			text: "Goodbye World!"

		

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