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.
from Tkinter import *
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()
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
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:
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.
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.
http://www.pyinstaller.org/ Install from here and follow their steps if you cant understand ,watch you tube tutorials to install the pyinstaller software.
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.
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
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.