Kivy is a platform independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications.
The Image widget is used to display an image. To use the image widget you must have to import :
from kivy.uix.image import Image, AsyncImage
because the module
kivy.uix.image have all the functionality related to images.
Images can be loaded to the Application via two types:
1) From system :
wimg = Image(source='mylogo.png')
2) Asynchronous Loading:
To load an image asynchronously (for example from an external webserver), use the AsyncImage subclass:
aimg = AsyncImage(source='http://mywebsite.com/logo.png')
Note: By default, the image is centered and fits inside the widget bounding box. If you don’t want that, you can set allow_stretch to True and keep_ratio to False.
Basic Approach to create multiple layout in one file: 1) import kivy 2) import kivyApp 3) import image 4) set minimum version(optional) 5) create App class 6) return Image/layout/widget 7) Run an instance of the class
Below is the code how can you use the images in your code:
Simple image from the system (must be in the folder in which the .py file is saved)
How can we add AsyncImage i.e. from the webserver(external)
Now one thing came in mind how can you change size, position, etc of the image the below code will explain that also:
- Python | Progress Bar widget in kivy
- Python | Spinner widget in kivy
- Python | Slider widget in Kivy
- Python | Switch widget in Kivy
- Python | Popup widget in Kivy
- Python | BoxLayout widget in Kivy
- Python | Checkbox widget in Kivy
- Python | Textinput widget in kivy
- Python | Scrollview widget in kivy
- Python | Carousel Widget In Kivy
- Python | Spinner widget in Kivy using .kv file
- Python | Switch widget in Kivy using .kv file
- Python | Popup widget in Kivy using .kv file
- Python | Progressbar widget in kivy using .kv file
- Python | Carousel Widget In Kivy using .kv file
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai