In this video I’ll show you how to add images to your Kivy app.

Using images with Kivy is pretty simple. We just create an image tag in our .kv language file and set the source to wherever the image is sitting on our computer.

We’ll also look at using “allow_stretch” and “keep_ratio” to change the size of our image to stretch or not.

Python Code: images.py
GitHub Code: images.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
#from kivy.uix.image import Image

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

class MyLayout(Widget):
	pass

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

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



Kivy Design Code: images.kv
GitHub Code: images.kv

<MyLayout>
	
	BoxLayout:
		orientation: "vertical"
		size: root.width, root.height
		
		#padding: 50
		#spacing: 20

		Image:
			source: 'images/aspen.png'
			allow_stretch: True
			keep_ratio: True

		#Button:
		#	text: "Hello 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