Building Cross-Platform Apps with Kivy & Python

In this Kivy & Python article we want to talk about Building Cross-Platform Apps with Kivy & Python, Kivy is Python framework that enables developers to create cross-platform mobile and desktop applications using Python programming language. Kivy provides alot of widgets for creating graphical user interfaces (GUI) that works on different platforms including Windows, macOS, Linux, iOS and Android.

 

 

Building Cross-Platform Apps with Kivy & Python

First of all we need to install Python Kivy.

 

 

After that you have installed Kivy, next step is to create new Kivy app. you can create a new Kivy app by creating new Python file and importing the necessary Kivy modules like this.

in this example we have imported necessary Kivy modules and created new class called MyApp that extends from App class. we have defined build() method for the class that returns  Label widget with text Welcome to geekscoders.com.

And lastly we have added conditional statement to check if the file is being run as the main code. if it is, we creates new instance of the MyApp class and call its run() method to start app.

 

 

Run the complete code and this will be the result

Building Cross-Platform Apps with Kivy & Python
Building Cross-Platform Apps with Kivy & Python

 

 

In the previous example we have created simple cross platform App with Kivy & Python, now let’s add event to our GUI app, for example iam going to create a button in my GUI app and after clicking of the button i want to change the text of the label.

In this updated example we have added a BoxLayout widget to the app and added a Label and  Button widget to the layout. we have also defined an on_button_click() method that is called when the button is clicked.

for handling button click event, we have used bind() method to bind on_press event of the Button widget to on_button_click() method. when the button is clicked, on_button_click() method is called and the label text is updated.

 

 

Run the code click on the button and this will be the result

Building Cross-Platform Apps with Kivy & Python
Building Cross-Platform Apps with Kivy & Python

 

 

 

Learn More on Kivy

Leave a Comment