What is Kivy ?
What is Kivy ?
- It also supports multitouch events.
- The applications made using Kivy will similar across all platforms but it also means that the applications fell or look will differ from any native application.
- A graphical library OpenGL ES 2.
- An extensive range of widgets that support multi-touch.
- An intermediate Kivy language to design custom widgets.
- An extensive support for input devices such as a mouse, keyboard, TUIO, as well as OS-specific multi touches events.
- Kivy is an opensource multi-platform GUI development library for Python and can run on iOS, Android, Windows, OS X, and GNU/Linux.
- It helps develop applications that make use of innovative, multi-touch UI.
Features of Kivy
There are the following cool features of Kivy
Features of Kivy
- Kivy includes various modules to play video files and streams.
- Kivy Video player also supports some common requirements related to videos such as play, pause, stop buttons, text that can be used as a subtitle, display messages to the user on videos, and more.
Example: Pygame video provider supports MPEG1 on Linux.
2. Multi-touch and gestures
- Kivy uses a wide range of widgets that support multi-touch and gestures.
- Kivy developers provide a gesture library to record the user's gesture.
- There are the following three gestures that we can record -
- Left to right horizontal line
- Right to left horizontal line
- Bottom to top vertical line
3. UI features
- Kivy comes with a number of widgets and controls to make our mobile interface more attractive and beautiful.
- It is also used to improve one-handed usability, navigate gestures, create new icons or design elements, dark mode, and new animations.
4. Visual effects and OpenGL
- Kivy uses PyGame for easily creating new games.
- PyGame comes with various modules to drawing shapes, dealing with colors, and playing music.
- Kivy is more flexible because it can run on a variety of devices, including Linux, mobile phones, windows tablets, iOS, and Raspberry .Pi.
- Kivy is flexible so it can adapt to new technologies quickly.
- Kivy framework is completely free to use. To work with Kivy you must have 1 GHz 32 bit (x86), or 64 bit (x64) CPU, 1 GB of RAM, 128 MB of graphical memory, and Python installed on your system.
Advantages & Disadvantages of Kivy
- A list of advantages of Kivy is given below -
- It helps us to design innovative user interfaces with multi-touch functionalities.
- It can smoothly work with various platforms such as Windows, Android, Linux, iOS, macOS, and Raspberry Pi.
- It helps us to run code on all supported platforms.
- It provides well-documented APIs.
- It offers a better representation of programs, including classes, widget configuration, and inherited classes.
- It performs better than HTML 5.
- Kivy uses kV language, which is not suitable for us to compile our code alone.
- It is not always up-to-date with the latest Android APIs.
- It takes a lot of time for building and compiling mobile applications.
- The sizes of the package are unnecessarily huge.
- It has a lack of community support.
Architecture of Kivy
Architecture of Kivy
1. Core Providers and Input Providers
- Kivy Providers mainly abstract the various core tasks includes opening a window, displaying images and text, playing audio, spelling correction, fetching images from a camera, and so on.
- An input provider is a piece of code that helps us to add support for a specific input device such as TUIO, mouse emulator, or Apple's trackpads.
- We can also add support for new input devices by providing a new class that reads our input data from our device and transform them into Kivy events.
- Kivy Graphics APIs have the ability to automatically optimize the drawing commands.
Core provides the following features -
- A clock is used to schedule the timer events. Clock supported both one-shot timers and periodic timers.
- In Kivy, the cache is used to store python objects. We can control the cache in the following two ways -
- Object limit
The UIX module commonly contains Widgets and Layouts to quickly create a user interface.
- Widgets are the user interface components that we add to our program to provide some kind of functionality.
- Example: file browser, buttons, lists, sliders, and more.
- Layouts are used to arrange widgets.
- Modules are the classes that can be loaded on the Kivy when we start the Kivy application.
- The config file is used to manage the loading of modules.
Kivy Installation on Windows
- Copy-paste the following link on any browser or you just simply click on the following link - Python
- The following page appears on the screen, in which click on the Downloads and select Windows from the drop-down menu.
- Select the Python Releases version for windows
- Double click on the downloaded file, the below window appears on the screen in which click on Install Now.
- The below screenshot shows that Python installation is in progress.
- The below screenshot shows that the setup is installed successfully. You just simply click on the Close button.
Follow the Below Steps to Download Anaconda
- Click on the below link to install Anaconda
- The following page appears on the screen. Scroll down the window and click on 64-bit Graphical Installer (446 MB) at the bottom of the screen.
- You can see that Anaconda Graphical Installer is to started download. Once the file is downloaded, double click on that executable file. The following window appears on the screen in which click on the Next.
- A License Agreement window appears on the screen, in which click on I Agree.
- Here choose type of Installation, select Install for Just Me (recommended)
- Browse the location where you want to install Anaconda and click on the Next.
- Advanced Installation Options window appears on the screen, tick on Register Anaconda3 as my default Python 3.7. And click on the Install
- The below screenshot shows that Anaconda Installation is in progress.
- Once the Installation process is completed, click on the Next button.
- The following window appears on the screen in which click on the Next.
- A completing Anaconda set up window appears on the screen, simply click on the Finish on that window.
- Once you installed the Anaconda, now we are able to install kivy.
There are the following steps to install kivy -
- Go to the Anaconda Prompt.
- Before installing kivy, first update the
pipby using the following command.
- Install the Dependencies
- There are the following 3 dependencies that we need to install while installing the Kivy.
- Use the following command to install Kivy.
Create a Hello World program in Kivy
There are the following steps to create a Hello World program in Kivy
- Open any text editor (Notepad or Notepad++)
- Write the following code on the Editor.
Hello World Program in Kivy
Add Image Widget in Kivy
- Kivy image widget uses kivy.uix.image module to display image.
- There are the following two ways to add images in Kivy.
- From system, image widget is used to load images from the system.
- The below code is used to add an image widget in Kivy
Add Image in Widget
- Buttons are an essential part of every application.
- It performs some specific tasks when we click on the button.
- The main advantage of a button is that it allows users to interact with the software and application directly.
- To create a button in Kivy, we need to import Button form kivy.uix.button.
- Label widget is used for rendering the text. To make labels more attractive, we can add font size, color, and text color in the label.
- To create label, we need to import from kivy.uix.label import Label module
- The below screenshot shows the output of the label.
- Switch widget contains only two states (On or OFF).
- We need to import from kivy.uix.switch import Switch module.
- The below screenshot shows the output of the Switch Widget.
- Progress Bar is one of the most important graphical control element, which is used to analyze the progress of operation such as downloading progress, file transfer progress, loading app, saving updates, and installation progress.
- When we click on the Start, the below progress bar appears on the screen.
- Layout is the most important term in graphics design.
- It is used to arrange elements for a better look.
- There are the following different types of layout that we generally use in the Kivy.
- GridLayout is designed to arrange the components in the form of a rectangular grid. In GridLayout, every rectangular grid is exactly the same in size.
- BoxLayout is used to arrange the component based on the axis's [along X-axis (horizontally) and along Y-axis (Vertically)].
- FloatLayout is used to place element according to the size of the current window (in terms of height and width of window).
- FloatLayout contains pos_hint and size_hint, which are the properties of its children.
- AnchorLayout is used to align the border top, bottom, left, right, or center.
- AnchorLayout is initialized using the below parameters:
- anchor_x = (Parameter can be passed: "left", "right", and "center")
- anchor_y = (Parameter can be passed: "top", "bottom", and "center")
- StackLayout helps us to arrange buttons vertically and horizontally. In StackLayout, it is not compulsory that the sizes of all buttons are the same, so we can arrange buttons according to our requirement.
Create a Popup Window in Kivy
- Popup window is a type of window that suddenly pops up on the screen. A popup window appears to users when they visit a page or closes a window.
- The below screenshot shows the output of popup window.
- When we click on the popup window, the following screen appears on the screen.
Create Popup Window
Create a Sign in Window in Kivy
- We are going to create a simple sign in page using Kivy. To create a sign in page in kivy, we need to create the following two files -
Case 1: If the username and the password are empty, then the following screen appears on the screen.
Create Signin Window
Case 2: If we enter username admin and password is admin then the following screen appears on the screen.
Create Signin Window