In this Python and Kivy article we want to learn about Introduction to Python and Kivy, so first of all let’s talk about Python, so Python is powerful and popular programming language that is used for different types of applications including web development, data analysis and scientific computing. Kivy is free and open source Python framework for creating cross platform user interfaces that can run on desktop computers, mobile devices and even embedded systems. in this article we want to introduce you Python and Kivy, and shows you how to get started with building your own cross platform apps.
What is Python Kivy ?
Kivy is Python framework for building multi touch applications. it is designed to be cross platform, which means that you can develop your applications that you can deploy it on multiple platforms such as Windows, Mac, Linux, Android and iOS. Kivy uses declarative language for designing UIs, and that is called KV language. KV language is similar to JSON and allows you to define the structure and layout of your UI in clear and easy way.
First if all we nee to install Python Kivy and you can use pip command for that.
1 |
pip install kivy |
this is an example of simple KV file that defines label and button, this KV file defines a Label widget with text Welcome to geekscoders.com, and a Button widget with text Click me. when you run this KV file using the Kivy framework, it will display a window with a label and a button, right now we are not going to talk about kv file.
1 2 3 4 5 |
Label: text: "Welcome to geekscoders.com" Button: text: "Click me" |
So this is an example of simple Python code that creates a Kivy window with label and button.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
from kivy.app import App from kivy.uix.label import Label from kivy.uix.button import Button from kivy.uix.boxlayout import BoxLayout class MyWidget(BoxLayout): def __init__(self, **kwargs): super(MyWidget, self).__init__(**kwargs) self.orientation = "vertical" self.label = Label(text="Welcome to geekscoders.com") self.add_widget(self.label) self.button = Button(text="Click me!") self.add_widget(self.button) class MyApp(App): def build(self): return MyWidget() if __name__ == "__main__": MyApp().run() |
Run the complete code and this will be the result