Program For Calculator In Python With Source Code
The Program For Calculator In Python is written in python programming language,In this article I will teach you on How To Make Calculator In Python or How To create a Calculator In Python.
Python has a design philosophy which emphasizes code readability. That’s why python is very smooth to use mainly for novices who just started programming. It is very smooth to research the syntax emphasizes clarity and it could reduces time consuming in developing.
Watch the Running Calculator project here.
A Calculator Python Program was design in Calculator In Python GUI or Graphical User Interface using Calculator In Python Tkinter, This article also includes the downloadable Calculator Python Code for free.
To start creating the Program For Calculator In Python, make sure that you have PyCharm IDE installed in your computer.
Steps on how to create a Program For Calculator In Python With Source Code
Program For Calculator In Python With Source Code
- Step 1: Create a project name.
First open PyCharm IDE and then create a “project name” after creating a project name click the “create” button.
- Step 2: Create python file.
Second after creating a project name, “right click” your project name and then click “new” after that click the “python file“.
- Step 3: Name your python file.
Third after creating a python file, Name your python file after that click “enter“.
- Step 4: The actual code.
Fourth is the actual coding on How To create a Calculator In Python and you are free to copy the given code below and download the full source code below.
The code given below is for importing module.
1 |
from tkinter import* |
In this piece of code which is importing the tkinter module for the design of this project.
The code given below is for the design or GUI of this project.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
def fCalc(src, side): appObj = Frame(src, borderwidth=4, bd=2,bg = "#cccccc") appObj.pack(side=side, expand=YES, fill=BOTH) return appObj def button(src, side, text, command=None): appObj = Button(src, text=text, command=command) appObj.pack(side=side, expand=YES, fill=BOTH) return appObj class app(Frame): def __init__(self, root = Tk(), width=364, height=425): Frame.__init__(self) self.option_add("*Font", 'arial 20 bold') self.pack(expand=YES, fill=BOTH) self.master.title("Simple Calculator") screen_width = root.winfo_screenwidth() screen_height = root.winfo_screenheight() x = (screen_width/2) - (width/2) y = (screen_height/2) - (height/2) root.geometry('%dx%d+%d+%d' % (width, height, x, y)) display = StringVar() Entry(self, relief= RIDGE, textvariable=display, state=DISABLED, justify='right', bd=20, bg="silver").pack(side=TOP, expand=YES, fill=BOTH) clrChar = "Clear" button(self, TOP, clrChar, lambda appObj=display, i=clrChar: appObj.set('')) for btnNum in ("789/", "456*", "123-", "0.+"): FunctionNum = fCalc(self, TOP) for fEquals in btnNum: button(FunctionNum, LEFT, fEquals, lambda appObj=display, i=fEquals: appObj.set(appObj.get() + i)) EqualsButton = fCalc(self, TOP) for fEquals in "=": if fEquals == "=": btnEquals = button(EqualsButton, LEFT, fEquals) btnEquals.bind('<ButtonRelease-1>', lambda e, s=self, appObj=display: s.result(appObj), "+") else: btnEquals = button(EqualsButton, LEFT, fEquals, lambda appObj=display, s=" %s "%fEquals: appObj.set(appObj.get()+s)) |
In this module which is the codes for the design of this project.
The code given below is for displaying the result.
1 2 3 4 5 |
def result(self, display): try: display.set(eval(display.get())) except: display.set("UNDEFINED") |
In this module which displaying the result you’ve enter in the text field, with conditioning.
Complete Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
from tkinter import* def fCalc(src, side): appObj = Frame(src, borderwidth=4, bd=2,bg = "#cccccc") appObj.pack(side=side, expand=YES, fill=BOTH) return appObj def button(src, side, text, command=None): appObj = Button(src, text=text, command=command) appObj.pack(side=side, expand=YES, fill=BOTH) return appObj class app(Frame): def __init__(self, root = Tk(), width=364, height=425): Frame.__init__(self) self.option_add("*Font", 'arial 20 bold') self.pack(expand=YES, fill=BOTH) self.master.title("Simple Calculator") screen_width = root.winfo_screenwidth() screen_height = root.winfo_screenheight() x = (screen_width/2) - (width/2) y = (screen_height/2) - (height/2) root.geometry('%dx%d+%d+%d' % (width, height, x, y)) display = StringVar() Entry(self, relief= RIDGE, textvariable=display, state=DISABLED, justify='right', bd=20, bg="silver").pack(side=TOP, expand=YES, fill=BOTH) clrChar = "Clear" button(self, TOP, clrChar, lambda appObj=display, i=clrChar: appObj.set('')) for btnNum in ("789/", "456*", "123-", "0.+"): FunctionNum = fCalc(self, TOP) for fEquals in btnNum: button(FunctionNum, LEFT, fEquals, lambda appObj=display, i=fEquals: appObj.set(appObj.get() + i)) EqualsButton = fCalc(self, TOP) for fEquals in "=": if fEquals == "=": btnEquals = button(EqualsButton, LEFT, fEquals) btnEquals.bind('<ButtonRelease-1>', lambda e, s=self, appObj=display: s.result(appObj), "+") else: btnEquals = button(EqualsButton, LEFT, fEquals, lambda appObj=display, s=" %s "%fEquals: appObj.set(appObj.get()+s)) def result(self, display): try: display.set(eval(display.get())) except: display.set("UNDEFINED") if __name__ == '__main__': app().mainloop() |
Output

Run Quick Virus Scan for secure Download
Run Quick Scan for secure DownloadDownloadable Source Code
I have here the list of Best Python Project with Source code free to download for free, I hope this can help you a lot.
Summary
The Program For Calculator In Python is written in python programming language, Python has a design philosophy which emphasizes code readability. That’s why python is very smooth to use mainly for novices who just started programming. It is very smooth to research the syntax emphasizes clarity and it could reduces time consuming in developing.
Project file contains the python script (simple_calculator.py). In this article can help the beginners in developing python programming language, and also can develop their skills in programming because the syntax and the logic in this python programming is easy to catch up and understand.
Related Articles
- Login Page in Python with MySql Database with Source Code
- CRUD Operations In Python With Source Code
- Complaint Management System Project in Python with Source Code
- How To Print Sum Of Two Numbers In Python With Source Code
- Best Python Project with Source code free to download
- Hotel Management System Project in Python With Source Code
- Student Management System Project in Python with Source Code
- How To Make A Point Of Sale System In Python
- Best Python Projects for Beginners
- Python MySQL Connection: Simple Python Step by Step Guide
- Python PIP Command Set-up / Fix: Step by Step Guide
- Random Password Generator in Python Projects With Source Code 2020
- Python Range Function|Range in Python Explained with Examples 2020
- Billing System Project in Python Project With Source Code
- Employee Payment Management System Project in Python
- School Management System Project In Python With Source Code
- Bank Management System Project in Python With Source Code
Inquiries
If you have any questions or suggestions about Program For Calculator In Python, please feel free to leave a comment below.