Machine Learning

Mobile App Development Works Python | Looking at the data science

Mobile app development Is the process of building a system for mobile devices, such as smartphones and tablets. Generally, mobile applications are difficult to develop than web apps, because it should be designed from the beginning of each platform, while the web development joins ordinary codes for all different devices.

Each functioning app has its own language used to enter codes of Native app (One was created with technology dedicated to a particular area). For example, Android uses Java, while IOS uses fast. Usually, it is better to use dedicated technology for applications that require high performance, such as playing or heavy pictures. On the contrary, Hybrid apps Use Cross-Platform languages ​​(ie Python) that can be conducted in many operating systems.

The development of mobile app is highly related to AI as enabling the integration of new technologies becoming people of daily life. The llMS is popular now because they have been sent to easy-useed apps in your phone, are readily available at any time.

With this lesson, I will explain How to create a CROSS-Platform mobile app for Python, Using my Memoizer app as an example (the full code link at the end of the article).

Putting Time

I will use Kivy framewhich is used for the development of mobile phones in the Python community. Initiative one is a package open source of mobile apps, while Kivymd by the library to enhance Google's Design for material and make the use of this framework for a very easy (such as the Web Dev) boots.

## for development
pip install kivy==2.0.0
pip install kivymd==0.104.2

## for deployment
pip install Cython==0.29.27
pip install kivy-ios==1.2.1

The first thing to do is done to create 2 files:

  • main. (Name must be) that will contain the App code for the app, basically end
  • Features.kv (You can call a different way) containing everything Initiative one Code used for app shape, you can see as one previous end

Then, in main. The file imports a package to start an empty app:

from kivymd.app import MDApp

class App(MDApp):
   def build(self):        
       self.theme_cls.theme_style = "Light"        
       return 0

if __name__ == "__main__":    
   App().run()

Before we started, I will briefly explain the app that I'm up to. An easy app to memorize items: The user includes pair of words (meaning something in English and equivalent to other language, or historical event related). After that, the user can play this game by trying to remember the potential information. In fact, I use memorizing Chinese vocabulary.

As you can see in the picture, I will include:

  • Intro screen to indicate the logo
  • Home screen that can redirect other screens
  • Saving screen
  • View screen and delete database
  • The game playlist.

Therefore, we can write all down in the Features.kv File:

To install Initiative one File in app, we need to upload from the main. In the construction class, when the screen screen connects screens between two files.

from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen

class App(MDApp):
   def build(self):        
       self.theme_cls.theme_style = "Light"        
       return Builder.load_file("components.kv")

class IntroScreen(Screen):    
   pass 

class HomeScreen(Screen):    
   pass 

class PlayScreen(Screen):
   pass  
 
class SaveScreen(Screen):    
   pass 

class EditScreen(Screen):
   pass

if __name__ == "__main__":    
   App().run()

Please note that no application itself is basic, there is a tricky defective feature: DB management by mobile. That is why we will also use the traditional Python for details:

import sqlite3

Development – Foundations

We will warm with Screen: It's just contains a picture logo, other text labels, and a button to move to another screen.

I think it's easy because it doesn't need Python code, not treated by Features.kv file. The screen switching caused by the button should be linked to the root such as:

The same is moving Home screen: Since he is just redirected, unpredicted Initiative one code. You just have to specify that the screen must have 1 icon and 3 button.

You may have seen that on top of the screen are the “Home” icon. Please note that there is a difference between a simple icon and the icon button: the last repeated. On this screen it is just a simple icon, but in some screens it will be an icon button used to restore on the home screen from any app screen.

When we use the icon, we should provide the mark (meaning that the home “shows a small house). I find this code very useful, just get rid of all the icons available.

Development – Advanced

Let's climb our game and face DB through Save the screen. You must allow the user to preserve different names in different categories (which means studying multilingual languages). That means:

  • To select the existing class (ie Chinese), so asking the existing
  • To create a new paragraph (ie french)
  • Scripture input (ie the name and its translation)
  • The form button stores, so writing a new line in DB.

If you run the app for the first time, DB must be created. We can do that in the main functioning of the app. For convenience, I will add to another job that reads DB by any SQL passing.

class App(MDApp):

   def query_db(self, q, data=False):        
       conn = sqlite3.connect("db.db")        
       db = conn.cursor()        
       db.execute(q)        
       if data is True:            
           lst_tuples_rows = db.fetchall()        
       conn.commit()        
       conn.close()        
       return lst_tuples_rows if data is True else None

   def build(self):        
       self.theme_cls.theme_style = "Light"
       q = "CREATE TABLE if not exists SAVED (category text, left
            text, right text, unique (category,left,right))"      
       self.query_db(q)
       return Builder.load_file("components.kv")

A deceptive part is a DB icon, when pressured, shows all the existing categories and allows one selection. In Features.kv File, under the last screen (the word “Keep “), We enter the icon button (the word “Category_dropdown_Save“) That, when pressed, notes Python Dropdown_save () Work from the main app.

That work is described in main. The file also returns such drop menu, where the object is pressured to be given a variety of so-called “kind“.

That code last line is linking kind Different in the label from the end. The screen manager calls the screen with Get_screen () and points the item by maturity:

When the user logs into the last screen, I kind the variable should be interpretation until one selected. We can specify the screenshots where the other comes in and when the person leaves. So I will add a task to the screen delete app flexibility.

class SaveScreen(Screen):    
   def on_enter(self):        
       App.category = ''

When the phase is selected, the user can include the replacement of the text, which is required to save the form (by pressing the button).

To make sure that the work does not stop if one of the installs empty, I will use the dialog box.

from kivymd.uix.dialog import MDDialog

class App(MDApp):    
  dialog = None     
  
  def alert_dialog(self, txt):        
     if not self.dialog:            
        self.dialog = MDDialog(text=txt)        
     self.dialog.open()        
     self.dialog = None

  def save(self):
     self.category = self.root.get_screen('save').ids.category.text  
          if self.category == '' else self.category            
     left = self.root.get_screen('save').ids.left_input.text            
     right = self.root.get_screen('save').ids.right_input.text            
     if "" in [self.category.strip(), left.strip(), right.strip()]:                
          self.alert_dialog("Fields are required")            
     else:                
          q = f"INSERT INTO SAVED VALUES('{self.category}',
                '{left}','{right}')"                
          self.query_db(q)                
          self.alert_dialog("Saved")                  
          self.root.get_screen('save').ids.left_input.text = ''                
          self.root.get_screen('save').ids.right_input.text = ''                
          self.category = ''

After reading so far, I'm sure you are able to pass the perfect code and understand what happens. The Logic of Other Screens is well matched.

Try

You can check the app in IOS Simulator in MacBookThat repeats iPhone Nature without requiring a virtual iOS device.

Xcode requires the installation. Start by opening terminal and using the following commands (the last one will take up to 30 minutes):

brew install autoconf automake libtool pkg-config

brew link libtool

toolchain build kivy

Now determine your app name and use it to create the last place, and open the.XCODEP File:

toolchain create yourappname ~/some/path/directory

open yourappname-ios/yourappname.xcodeproj

Finally, if you work with iOS and you want to check the app on your phone and publish it in the app store, Apple requires you to pay an engineer account.

Store

This article has been a lesson to show How to design a cross-platform mobile app for Python. I used Initiative one To create a user interface and show how I do available to IOS devices. You can now do your mobile apps with Python and Initiative one.

The full code of this article: A Kiki tree

I hope you enjoy! Feel free to contact me with questions and feedback or just to share your exciting projects.

👉 Let's get on contact 👈

(All photos, unless noted in another manner, they are a writer)

Source link

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button