This is our first article on Kivy Crash Course, in this article we are going to talk about Kivy Introduction & Installation. Kivy is an open source, cross-platform Python framework for the development of applications that make use of innovative, multi-touch user interfaces. The aim is to allow for quick and easy interaction design and rapid prototyping whilst making your code reusable and deployable. Kivy is written in Python and Cython, based on OpenGL ES 2, supports various input devices and has an extensive widget library. With the same codebase, you can target Windows, macOS, Linux, Android and iOS. All Kivy widgets are built with multitouch support.
Also you can watch the video for this article
Read more articles on Python GUI Development
Installation
You can simply install kivy with pip, if you are using window. also before installation you need to install the dependency for kivy, after that install kivy.
1 |
pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew |
1 |
pip install kivy |
for installation of other operating systems you can check their documentation, Kivy Installation.
Now let’s create our first window in Kivy, so this is the code for creating our first basic window in kivy.
1 2 3 4 5 6 |
from kivy.app import App app = App() app.run() |
so just in the top we have imported the App class from kivy, after that we have created the object of our App class, and this App class is the initial point for creating of our window. and after you need to just run your app object. after run you will see this result.
So now let’s extend our code and also create a label widget in Kivy.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
from kivy.app import App from kivy.uix.label import Label class Window(App): def build(self): #return Label(text = "Hello Kivy Application", font_size = '25sp') return Label(text = '[color=ff3333]Hello[color=3333ff]Kivy Application' ,markup=True,font_size = "30sp") if __name__ == "__main__": window = Window() window.run() |
OK in the above code you can see that first we have imported our required classes from kivy, basically we are going to use App class with Label class. after that we have created our window class that extends from app class. the app class is the starting point of any kivy application.
1 2 3 4 |
def build(self): #return Label(text = "Hello Kivy Application", font_size = '20sp') return Label(text='[color=ff3333]Hello[color=3333ff]Kivy Application', markup = True, font_size = '30sp') |
This method returns the window content. in this case a simple colorful label saying Hello Kivy Application.
Run the complete code and this will be the result
Subscribe and Get Free Video Courses & Articles in your Email