Computer Science, asked by sohamdas207, 9 months ago

How we can make an app using python ? Explain in detail.​

Answers

Answered by Anonymous
3

Python doesn't have built-in mobile development capabilities, but there are packages you can use to create mobile applications, like Kivy, PyQt, or even Beeware's Toga library. These libraries are all major players in the Python mobile space.

Answered by Punika31
2

Step 1: Intro to GUI

Intro to GUI

First, we need to begin a GUI. Nothing but a Graphical User Interface for all your codes.

That is you might have run the program on the command line and got the output in the same. But to make your code interacting with the user you need an Interface to communicate.

Creating GUI with python is very easy... Lets start

There are many modules in the python which you can import and code your GUI. Tkinter is the built-in GUI for the python, It comes installed with your python software. Also, you may also try PyQT, Kivy(best for cross-platform ie same code in python can be used to create apk, exe or MAC software)

Here in this Instructables, I am going to use the Tkinter. The simple thing in python is that you can import other python files to your, same way you need to import the Tkinter python, as similar to #include in C.

Explanations:

here Tk()refers to the class in the

Tkinter module we are saving initializing to top,

Label is the method(function as in other languages) to print a text in,

Entry method to create a blank entry and

Button is to create button , As simple as that ....isn't it

pack is key to package everything it the layout.... finally main loop keeps everything visible until you close the GUI

Step 2: Building Our Own Calculator

Now we have seen a simple GUI with the buttons, So why to wait, lets start building a simple calculator with buttons.

Note:

There can be n number of ways of creating the code, here I only illustrate the code which is easier for me

Sub Step 1: Creating GUI

Before going to the code we can create a GUI for our calculator application.

Here I am going to use only one button and 4-row entry for easy understanding.

thus simple copy paste of every label, entry and button we created of the previous step ... Don't panic by the length of the code...! haha

Sub Step 2: Main Code

Here in our case what has to happen... just after entering 2 numbers and specifying the operation in between them, the answer has to be printed or displayed in the answer entry.

1.Submit button command:

We need to give to give the command to the button to call a method that is what is designed.

Here I have called the Method (function ) process, so after pressing the button program goes and knocks the door of the function process in simpler terms.

and get here means get the value the user has entered. Also, I stored in the 3 variables namely as number1, number2, operator

Just to make it meaningful I have kept process you may keep the name of the method as per your wish.

Step 3: Process

Process

In this step, we need to process the input received from the user,

But by default, the value received is a string.

So how to convert it to an integer to perform calculation...?

So nothing to worry it is python and not C or C++ to squeeze your brain.

Simply enter the variable in int(variable)

number1= int(number1)

number2=int(number2)

String in python is denoted by " " thats here in the if we are checking the string operator recived from the user to the string +,-,*/ etc, and storing the result in the answer variable.

Now at last we need to send the output to the answer entry,

this is done by the insert code.

thus finally our code looks like :

from Tkinter import *

import Tkinter

import tkMessageBox

def proces():

   number1=Entry.get(E1)

   number2=Entry.get(E2)

   operator=Entry.get(E3)

   number1=int(number1)

   number2=int(number2)

   if operator =="+":

       answer=number1+number2

   if operator =="-":

       answer=number1-number2

   if operator=="*":

       answer=number1*number2

   if operator=="/":

       answer=number1/number2

   Entry.insert(E4,0,answer)

   print(answer)

top = Tkinter.Tk()

L1 = Label(top, text="My calculator",).grid(row=0,column=1)

L2 = Label(top, text="Number 1",).grid(row=1,column=0)

L3 = Label(top, text="Number 2",).grid(row=2,column=0)

L4 = Label(top, text="Operator",).grid(row=3,column=0)

L4 = Label(top, text="Answer",).grid(row=4,column=0)

E1 = Entry(top, bd =5)

E1.grid(row=1,column=1)

E2 = Entry(top, bd =5)

E2.grid(row=2,column=1)

E3 = Entry(top, bd =5)

E3.grid(row=3,column=1)

E4 = Entry(top, bd =5)

E4.grid(row=4,column=1)

B=Button(top, text ="Submit",command = proces).grid(row=5,column=1,)

Similar questions