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 | Carousel Widget In Kivy
- Python | BoxLayout widget in Kivy
- Python | Spinner widget in kivy
- Python | Switch widget in Kivy
- Python | Popup widget in Kivy
- Python | Slider widget in Kivy
- Python | Checkbox widget in Kivy
- Python | Switch widget in Kivy using .kv file
- Python | Popup widget in Kivy using .kv file
- Python | Spinner widget in Kivy using .kv file
- Python | Carousel Widget In Kivy using .kv file
- Python | Adding image in Kivy using .kv file
- Progressbar widget in Tkinter | Python
- Python | Slider widget using .kv file
- Python | Menu widget in Tkinter
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.