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.
1 |
pip install 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.
1 2 3 4 5 6 7 8 9 10 |
import kivy from kivy.app import App from kivy.uix.label import Label class MyApp(App): def build(self): return Label(text="Welcome to geekscoders.com") if __name__ == "__main__": MyApp().run() |
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

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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import kivy from kivy.app import App from kivy.uix.label import Label from kivy.uix.button import Button from kivy.uix.boxlayout import BoxLayout class MyApp(App): def build(self): # Create a BoxLayout layout = BoxLayout(orientation='vertical') # Add a Label widget to the layout self.label = Label(text="Welcome to geekscoders.com") layout.add_widget(self.label) # Add a Button widget to the layout button = Button(text='Click me') button.bind(on_press=self.on_button_click) layout.add_widget(button) return layout def on_button_click(self, button): self.label.text = 'Hello World - GeeksCoders.com' self.label.font_size = 30 if __name__ == "__main__": MyApp().run() |
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
