Start Developing Kivy Apps Right Away!
Creating Kivy apps is fun and rewarding. This guide should be the perfect starting point to get you on the right track for app development. You will require a basic knowledge of Python to follow this introduction.
Using Kivy on your computer, you can create apps that run on:
- Desktop computers: OS X, Linux, Windows.
- iOS devices: iPad, iPhone.
- Android devices: tablets, phones.
- Any other touch-enabled professional/homebrew devices supporting TUIO (Tangible User Interface Objects).
#INSTALLATION
If you want the development version of Kivy in order to benefit from the latest additions to the framework, you can get the source code from github:
git clone http://github.com/kivy/kivyinstallation on windows :
Using Conda |
conda install kivy -c conda-forge
Otherwise, continue below to install Kivy in a native Python installation.
Installing Kivy Stable Release
- Ensure you have the latest pip, wheel, and virtualenv:
python -m pip install --upgrade pip wheel setuptools virtualenv
- First create the environment named kivy_venv in your current directory:
python -m virtualenv kivy_venv
- Activate the virtual environment. You’ll have to do this step from the current directory every time you start a new terminal. On windows CMD do:
kivy_venv\Scripts\activate
source kivy_venv/Scripts/activate
- Install the dependencies (skip gstreamer (~120MB) if not needed, see Kivy’s dependencies). If you are upgrading Kivy, see Updating Kivy from a previous release:
python -m pip install docutils pygments pypiwin32 kivy_deps.sdl2==0.1.* kivy_deps.glew==0.1.* python -m pip install kivy_deps.gstreamer==0.1.*
NoteIf you encounter a MemoryError while installing, add after pip install the –no-cache-dir option.
python -m pip install kivy_deps.angle==0.1.*
WarningWhen installing, pin kivy’s dependencies to the specific version that was released on pypi when your kivy version was released, like above. Otherwise you may get an incompatible dependency when it is updated in the future. - Install kivy:
python -m pip install kivy==1.11.1
- (Optionally) Install the kivy examples:
python -m pip install kivy_examples==1.11.1
import kivy
in python or run a basic
example if you installed the kivy examples:python kivy_venv\share\kivy-examples\demo\showcase\main.py
Note
If you encounter any permission denied errors, try opening the
Command prompt as administrator
and trying again. The best solution for this is to use a virtual environment
instead.
In this section, you will learn how to create and run a Kivy program and how to build a basic interface in Kivy.
Let’s create a file with .py extension.
To create a Kivy interface, we first need to import the Kivy app module in our program using the following statement:
from kivy.app import App
Now importing Label from kivy.uix.label:from kivy.uix.label import Label
Now is the time to write our main program.class FirstKivy(App):
def build(self):
return Label(text="Hello Kivy!")
In the above snippet, a class is inherited from the App class.
Then to build the application we have to return a widget on the build()
function. In the code above, we have returned a label with text “Hello
Kivy”.The last step is to call this function. You can either create an object of the class or just write the following statement:
FirstKivy().run()
The entire python file looks like the following:from kivy.app import App
from kivy.uix.label import Label
class FirstKivy(App):
def build(self):
return Label(text="Hello Kivy!")
FirstKivy().run()
The result of this code will be like this:Part two of kivy tutorial coming soon...
No comments:
Write Comments