How to Make Your First Simple Software Using Python

202,984

36

27

Introduction: How to Make Your First Simple Software Using Python

Hi, welcome to this Instructables.Here I am going to tell how to make your own software. Yes if you have an idea... but do know to implement or interested in creating new things then it is for you......

Prerequisite: Should have basic knowledge of Python.... LOL Nothing like that,

"There is nothing difficult in this world if you try"

with simple interest to make things you can move on to start your program. Even me at the beginning had a no Idea of python.

Moreover as a Electrical at first I was afraid of Coding. Slowly I changed my mentality.

If you are a beginner at programming, start with python makes a fast curve to learn and as the output is very fast you get very excited to learn.

Here below video, you may see what you are going to get as output ...

OK without wasting much time we can move on to the subject.

Here in this instructable I am only going to share how to make a simple GUI with python also how to make it into a Software with "exe" and not much with python coding ..... you may refer youtube or udemy to learn Python course.

you may install python from here : https://www.python.org/downloads/


Step 1: 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) https://kivy.org/#home

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.

<p>from Tkinter import *<br>import Tkinter
import tkMessageBox
top = Tk()
L1 = Label(top, text="HI")
L1.pack( side = LEFT)
E1 = Entry(top, bd =5)
E1.pack(side = RIGHT)
B=Button(top, text ="Hello",)
B.pack()</p><p>top.mainloop()</p>

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

from Tkinter import *
import Tkinter import tkMessageBox

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",).grid(row=5,column=1,)

top.mainloop()

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. Lets see...

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

def proces():
number1=Entry.get(E1) number2=Entry.get(E2) operator=Entry.get(E3)

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

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)

Still, there is another problem... how to get the value of the operator (like +,-*/) to operate ???

Just make if statement for each and inside do the calculations.

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

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.

Entry.insert(E4,0,answer)

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,)

top.mainloop()

WOW, you have successfully created the code of the calculator........!! Its time to celebrate..

Step 4: Additional Contents (Part 1-Dialogue Box Exception Handling )

Heading Sounds like something Technical ....? Definitely not I will tell you the story why,.....

Consider you made this calculator and showing it to a friend.

He/she is a notorious person instead of typing the integer he types letters in the numbers entry and kids you ... what to do...? python produces the errors and stops right away....

Here comes the process of the pythons exception handling, also in many software and web pages produces alert or warning messages

Exception Handling in python

The exception handling is as simple has saying try and if any error show warning

Type the value of the in letters the console says Value error thus for it we can do the warning

Let us see how to do in our code:

def proces():
try: 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) except ValueError: tkMessageBox.showwarning("Warning","Please enter the value in integer")

Here we have made simple warning dialogue box and here as before tkMessageBox.showwarning is the custom warning for Tkinter and in the bracket Warning denotes the heading of the dialogue box and the next shows the message.




Step 5: Additional Contents (Part 2-Creating EXE )

Considering the fact that you have created your python code, and completely working after debugging errors... but there is a final problem, If you want to share your python code to others, they must be having the python installed this is not possible. Also If you wish not to disclose your code creating EXE is the best way.

thus to create the executable (exe) version or Apk (for Android ) must be made this can be made by freezing your code.

There are many such options to freeze your code one I would suggest is by using Pyinstaller.

step1:

http://www.pyinstaller.org/ Install from here and follow their steps if you cant understand ,watch you tube tutorials to install the pyinstaller software.

Step 2:

Then go to the folder where the code is present and press SHIFT +right click in mouse button and click open in command prompt or power shell depending on your OS version.

python pyinstaller.py --noconsole yourscript.py

pyinstaller.exe --onefile --windowed --name myapps --icon=yourico.ico yourscript.py

Thus you can also add your ico for your exe and bundle it up within one file with the second command.

Step 6: Conclusion

Thus Its up to your interest to create the final software,... Thanks for reading I will upload the final code and the exe in my GitHub link >> https://github.com/ranga95/instructables-calculato...

Also, I have created 2 software

1.Blender Batch Renderer

Short Explanation:

Blender is the animation software which we are using to do animation kinds of stuff... if interested please vist>>http://engineerthoughts.com/anim.html also our youtube.

It really takes sooo long to render output, there is no option in the blender to pause and render between, thus I made a software for it... It is little easy..... not very difficult for me to code at the beginning without any help..finally was able to make it. (it taught me nothing is difficult if you try).

2.Electronic Drum Beats Arduino to computer connection

Short Explanation:

It is a software which could read the piezo sensor from the Arduino and python software would play the music accordingly. ( This was made for my friend who asked it very long ....)

This Instructable is just an intro to create the software from the python as from I understanding,.... sorry If I was wrong in any part, as a beginner correct me in comments.

I will also add further in my Website : www.engineerthoughts.com

Soon I will make a tutorial for my software.

Feel free to ask any doubts in the comments section. I will be happy If you are benefited by this tutorial

Thank God and everyone

be happy, God is with you... all the best

With love

(N.Aranganathan)

6 People Made This Project!

Recommendations

  • Puzzles Speed Challenge

    Puzzles Speed Challenge
  • "Can't Touch This" Family Contest

    "Can't Touch This" Family Contest
  • CNC Contest 2020

    CNC Contest 2020

27 Discussions

0
Aadya123
Aadya123

Question 5 days ago

It didn't work for me. :( help is appreciated.

1
Nandu kamal
Nandu kamal

Question 9 months ago on Step 2

sir how can i make a software for billing purpose in a hotel

0
Ranga1995
Ranga1995

Answer 2 months ago

You have to read on fetching data in python from data bases and make a gui.
u can look into sqlalchemy packages of python for using sql in py

1
raushnichoudhary
raushnichoudhary

7 months ago

Sir i have to make a software which can differentiate between responders and no responders in cardiovascular disease can python script help in this???? Please reply

0
Ranga1995
Ranga1995

Reply 2 months ago

Yes u can make ur logic and do so

0
jayasunilB
jayasunilB

2 months ago

can i develop andriod app using your code

0
Ranga1995
Ranga1995

Reply 2 months ago

No....(In short)
Some of python GUI packages for android are Kivy etc
actually it is bitter truth that python is not good for android applications ...

you can either go for JavaScript or Java to make android application that would be fine.

Javascript is my personal recommendation as it could be easy for cross platform applications.

thank u

1
billing.indiaaccess
billing.indiaaccess

2 months ago

Very helpful tips,
I will use the same to solve issues of my company Indiaaccess Servers and Hostasp Servers
Thanks for your info

1
markrg
markrg

Question 3 months ago

Hi - thanks for posting such a good python project. I'm trying to learn it but having problems at very first stage for GUI. I'm using Windows 10 and Python 3.8.2. Will you code work on that version? Thanks, Mark

0
Ranga1995
Ranga1995

Answer 3 months ago

yes

1
Jjade483
Jjade483

6 months ago

Very helpful, thanks a lot!

1
DeDipNath
DeDipNath

1 year ago

First of all thank you so much, it's very helpful but sir I am not understanding the Step 5(creating EXE)-step 2, where those 2 lines of code have to write and save to create the exe file.Sir please reply.

0
Ranga1995
Ranga1995

Reply 10 months ago

super I will also suggest you to look into auto-py-to-exe that is very simple now. that is simple thing to convert to exe

1
lisa2mona5
lisa2mona5

10 months ago

Great!!

I was looking how to make python script executable and your instruction helped me

0
Ranga1995
Ranga1995

Reply 10 months ago

super I will also suggest you to look into auto-py-to-exe that is very simple now.

1
Shriman Akash
Shriman Akash

Question 12 months ago on Step 1

How can I execute this in tablets
is there any app available for executing this type of codings

0
Ranga1995
Ranga1995

Answer 10 months ago

use any python ide like pycharm or pyzo or spyder

0
mtahiransari786
mtahiransari786

1 year ago

Can I build software applications in visual studio with python?

0
iZapOptimum
iZapOptimum

1 year ago

How do I run this?

0
Ranga1995
Ranga1995

Reply 1 year ago

double click it