Kivy Tutorials
About Lesson

In this Kivy lesson we are going to talk about Kivy Image & Kivy AsyncImage, so the Image widget is used to display an image. to load an image asynchronously (for example from an external webserver), use the AsyncImage subclass.

 

 

We want to load our image in Kivy using two ways, the first way is that you can use Python code and the second way is that you can use Kivy Deign Language. using Python code we can use kivy.ui.image module.

 

 

This is the code make sure that you have already added an image in your working directory.

 

 

Using this code you can create the object of Image, also you need to add the image name, make sure that you have already added an image in your working directory.

 

 

You can change the position of the image using this code, you can give the x and y position for the image.

 

 

If you want to give opacity for the kivy image than you can use this code.

 

 

 

Run the complete code and this is the result.

Kivy Image & AsyncImage
Kivy Image & AsyncImage

 

 

 

Now let’s load the image using Kivy AsyncImage, for this you need to have internet connection, because we want to load an image using the url.

 

 

 

Run the complete code and this is the result.

Kivy AsyncImage
Kivy AsyncImage

 

 

 

 

Creating Image with KV Language

So now let’s create the image using the kivy file, so first of all this is my python code. in this code basically i have just created a new class that extends from the image class and i have returned that class in my main app class.

 

 

 

And this is our KV file, and i have name the file imagewindow.kv, make sure that this name should similar to the main app class name, in my case it is ImageWindow class.

 

 

 

Run the complete code and this is the result.

Kivy Image & AsyncImage
Kivy Image & AsyncImage