How to Make Your First Simple Software Using Python

262,429

47

47

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.

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.

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.

Kindly subscribe to my you tube channel engineer thoughts for future videos: Engineer thoughts

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)

9 People Made This Project!

Recommendations

  • First Time Author Contest

    First Time Author Contest
  • Water Speed Challenge

    Water Speed Challenge
  • Make it Fly Challenge

    Make it Fly Challenge

47 Comments

0
Ranga1995
Ranga1995

Reply 9 months ago

I don't think we can do in colab.

0
raghavam966
raghavam966

Question 6 months ago

Can I build software applications with python for the education system?

0
Simran Sharma
Simran Sharma

Question 7 months ago

How to connect MySQL on python?

0
Ranga1995
Ranga1995

Answer 6 months ago

You can use sqlalchemy which is good for sql in object oriented way of executing python program.

0
bahramit324
bahramit324

Question 6 months ago

How your function executed without calling it?

0
Ranga1995
Ranga1995

Answer 6 months ago

B=Button(top, text ="Submit",command = proces).grid(row=5,column=1,)
Here in this button named B, there is command= proces so whenever button is pressed, the "process" function is called which contains the calculator logic.

2
mtahiransari786
mtahiransari786

2 years ago

Can I build software applications in visual studio with python?

0
Simran Sharma
Simran Sharma

Reply 7 months ago

Of course you can build an application on visual studio.But for visual studio there is an Ironpython. Normally python shell, or any other ide based softwares have Cpython. You can learn of using python in visual studio in detail by searching on Google or YouTube.

0
Ranga1995
Ranga1995

Reply 10 months ago

yes for sure. sorry for the late reply.

0
Simran Sharma
Simran Sharma

Question 7 months ago

Is there any IDE softwares for python in which we can easily drag and drop the buttons,textfield on the frame like NetBeans for java?

0
jeremykoay1127
jeremykoay1127

8 months ago

I followed all the code you write but it appear the error AttributeError: 'NoneType' object has no atttribute 'tk'

0
DerrickGodwin
DerrickGodwin

Question 10 months ago

How can I create an online shopping app using Python?

0
Ranga1995
Ranga1995

Answer 10 months ago

Yes you can use web frameworks of python such as flask or django. You can link the database with any of the database through SQL query. Further You can use sqlalchemy in python for SQL commands.

0
DerrickGodwin
DerrickGodwin

Answer 10 months ago

Pls what is an IDE?

0
Ranga1995
Ranga1995

Reply 10 months ago

IDE is like a normal notebook or text editor, but it will have additional features such as highlighting the syntax of code which would be easy for debugging.

0
Ranga1995
Ranga1995

Answer 10 months ago

I don't remember it. I am currently using Spyder which comes along with Anaconda package.

2
chukscherem
chukscherem

10 months ago

Can you please make a video about these and more others on facebook or youtube