Kivy – Python Framework for Mobile App development

Kivy is a free and open-source Python library used for developing mobile applications and other multitouch application software with a Natural User Interface.

Installation

We can download the latest version of Kivy from here. After opening the link you can choose your Platform and follow the instructions specific for your platform.

Installation using PyCharm

  1. We will open PyCharm and Create a New Project and Name it as “Tutorial”(Project Name), we can Name as we want.
  2. We will Right click on “Tutorial”(Project Name) and create a new Directory Named as FirstApp.
  3. Inside this FirstApp We will create a Python file named as Main.
    1. To install Kivy follow:



      1. Goto File->Settings->Project:Tutorial(Project Name).
      2. Under Project: Tutorial(Project Name), Click on Project Interpreter.
      3. Then Click on ‘+’ Sign on top right and Search for Kivy you will see the following Screen:
        installing kivy

      Installing Kivy Dependencies

      Similarly Click on the following dependencies to install them :

      • kivy-deps.angle
      • kivy-deps.glew
      • kivy-deps.gstreamer
      • kivy-deps.sdl2

      Example 1 : Printing Welcome Message on Kivy App

      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      # import the modules
      from kivy.app import App
      from kivy.uix.label import Label
        
      # defining the Base Class of our first Kivy App
      class MyApp(App):
        
          def build(self):
        
              # initializing a Label with text ‘Hello World’ 
              and return its instance
              return Label(text = 'welcome to GeeksforGeeks')
        
        
      if __name__ == '__main__':
          # MyApp is initialized and its run() method called
          MyApp().run()

      chevron_right

      
      

      Output :
      Printing Message on Kivy App

      Example 2 : Creating Login Screen

      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      # importing the modules
      from kivy.app import App
      from kivy.uix.gridlayout import GridLayout
      from kivy.uix.label import Label
      from kivy.uix.textinput import TextInput
        
      # this class is used as a Base for our 
      # Root Widget which is LoginScreen 
      class LoginScreen(GridLayout):
        
          # overriding the method __init__() so as to 
          # add widgets and to define their behavior
          def __init__(self, **kwargs):
              super(LoginScreen, self).__init__(**kwargs)
        
              # GridLayout managing its children in two columns 
              # and add a Label and a TextInput for the Email id and password
              self.cols = 2
              self.add_widget(Label(text = 'Email id'))
              self.username = TextInput(multiline = False)
              self.add_widget(self.username)
              self.add_widget(Label(text = 'password'))
              self.password = TextInput(password = True, multiline = False)
              self.add_widget(self.password)
        
      class MyApp(App):
          def build(self):
              return LoginScreen()
        
        
      if __name__ == '__main__':
        
          # MyApp is initialized and 
          # its run() method called
          MyApp().run()

      chevron_right

      
      

      Output :
      login app

      Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

      To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




      My Personal Notes arrow_drop_up

      Check out this Author's contributed articles.

      If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

      Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


      Article Tags :

      Be the First to upvote.


      Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.