0% found this document useful (0 votes)
10 views

ScientificCalculatorInPython-CopyAssignment 1724530762391

Uploaded by

nikeonyemah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

ScientificCalculatorInPython-CopyAssignment 1724530762391

Uploaded by

nikeonyemah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

HOME WRITE N EARN 1000+ PROJECTS CONTACT US Search here...

SEARCH….

Search … Search Scientific Calculator in Python


 AYUSH PURAWR  NOVEMBER 7, 2022

SITEMAP
Who does not need a calculator in this era? Scientific calculators simply need an
hour; having one at our fingertips is helpful. Today we will learn about building a
Python
Scientific Calculator in Python. Having a scientific calculator is an absolute must
when it comes to a science student’s everyday requirements. Having a scientific
Machine Learning calculator on your screen greatly facilitates completing online projects, especially in
these days of online learning. Click here to copy the source code.

Pygame
Have you ever wondered about developing a GUI Scientific Calculator in Python? If
not, let’s learn to make one in this article on GUI Scientific Calculator in Python. Here
Data Structures and
in this article, we will take you through all the concepts that are important and also
Algorithms(Python)
provide you with the source code for your reference.

Python Turtle
Scientific Calculator in Python: Project
Games with Python
Overview

All Blogs On-Site Project Name: Scientific Calculator in Python using Tkinter

Abstract It’s a GUI-based project used with the Tkinter module to organize all the
elements that work under Scientific Calculator.
Python Compiler(Interpreter)
Language/s Used: Python

Online Java Editor IDE Thonny and PyCharm(Recommended)

Python version Python 3. x


Online C++ Editor (Recommended):

Database: None
Online C Editor
Type: Desktop Application
All Editors Recommended for Intermediate Python Programmers

Services(Freelancing) Python GUI Scientific Calculator with Code is a straightforward project created in
Python. This project is based on a straightforward GUI and is very simple to
comprehend and use. Additionally, the user may easily learn how to execute
RECENT POSTS
numerical computations with the help of this project. Like a typical calculator, the
project has numbers, operators, and signs. In order to enter any number or simply
Most Underrated Database Trick | Life-
click on the numbers they desire for the computations, the user needs only click. As
Saving SQL Command
a result, the user of this application can utilize a straightforward calculator.

Python List Methods

Features of Scientific Calculator


Top 5 Free HTML Resume Templates in
2024 | With Source Code
All basic operators like addition, multiplication, subtraction, and division.
Dedicated buttons for sin, cos, tan, and cot.
How to See Connected Wi-Fi Passwords
Functions for log
in Windows?
Functions for ratio and exponents.
Other buttons like Pi, mod, and x!
2023 Merry Christmas using Python
Turtle
Main Code

Now that we know what we are going to develop. Let us start our Scientific
Calculator in Python using the Tkinter development journey without wasting a single
second. An in-depth explanation along with source code will be definitely a good
experience to learn this project.

Basic library imports and window configuration

from tkinter import *


import math
import tkinter.messagebox

root = Tk()
root.title("Scientific Calculator")
root.configure(background = 'red')
root.resizable(width=False, height=False)
root.geometry("480x568+450+90")
calc = Frame(root)
calc.grid()

Explanation:
Here we imported some libraries and set up the title for our Scientific Calculator in
the Python window. We also used the geometry() function of the Tkinter library to set
the size of the window. Besides that, we have also used a grid() function to place
each and every box in its calculator at the correct position and designed the overall
calc in the form of a grid.

Class definition for all the Scientific Calculator functions

class Calc():
def __init__(self):
self.total=0
self.current=''
self.input_value=True
self.check_sum=False
self.op=''
self.result=False

def numberEnter(self, num):


self.result=False
firstnum=txtDisplay.get()
secondnum=str(num)
if self.input_value:
self.current = secondnum
self.input_value=False
else:
if secondnum == '.':
if secondnum in firstnum:
return
self.current = firstnum+secondnum
self.display(self.current)

def sum_of_total(self):
self.result=True
self.current=float(self.current)
if self.check_sum==True:
self.valid_function()
else:
self.total=float(txtDisplay.get())

def display(self, value):


txtDisplay.delete(0, END)
txtDisplay.insert(0, value)

def valid_function(self):
if self.op == "add":
self.total += self.current
if self.op == "sub":
self.total -= self.current
if self.op == "multi":
self.total *= self.current
if self.op == "divide":
self.total /= self.current
if self.op == "mod":
self.total %= self.current
self.input_value=True
self.check_sum=False
self.display(self.total)

def operation(self, op):


self.current = float(self.current)
if self.check_sum:
self.valid_function()
elif not self.result:
self.total=self.current
self.input_value=True
self.check_sum=True
self.op=op
self.result=False

def Clear_Entry(self):
self.result = False
self.current = "0"
self.display(0)
self.input_value=True

def All_Clear_Entry(self):
self.Clear_Entry()
self.total=0

def pi(self):
self.result = False
self.current = math.pi
self.display(self.current)

def tau(self):
self.result = False
self.current = math.tau
self.display(self.current)

def e(self):
self.result = False
self.current = math.e
self.display(self.current)

def mathPM(self):
self.result = False
self.current = -(float(txtDisplay.get()))
self.display(self.current)

def squared(self):
self.result = False
self.current = math.sqrt(float(txtDisplay.get()))
self.display(self.current)

def cos(self):
self.result = False
self.current = math.cos(math.radians(float(txtDisplay.get())))
self.display(self.current)

def cosh(self):
self.result = False
self.current = math.cosh(math.radians(float(txtDisplay.get())))
self.display(self.current)

def tan(self):
self.result = False
self.current = math.tan(math.radians(float(txtDisplay.get())))
self.display(self.current)

def tanh(self):
self.result = False
self.current = math.tanh(math.radians(float(txtDisplay.get())))
self.display(self.current)

def sin(self):
self.result = False
self.current = math.sin(math.radians(float(txtDisplay.get())))
self.display(self.current)

def sinh(self):
self.result = False
self.current = math.sinh(math.radians(float(txtDisplay.get())))
self.display(self.current)
def log(self):
self.result = False
self.current = math.log(float(txtDisplay.get()))
self.display(self.current)

def exp(self):
self.result = False
self.current = math.exp(float(txtDisplay.get()))
self.display(self.current)

def acosh(self):
self.result = False
self.current = math.acosh(float(txtDisplay.get()))
self.display(self.current)

def asinh(self):
self.result = False
self.current = math.asinh(float(txtDisplay.get()))
self.display(self.current)

def expm1(self):
self.result = False
self.current = math.expm1(float(txtDisplay.get()))
self.display(self.current)

def lgamma(self):
self.result = False
self.current = math.lgamma(float(txtDisplay.get()))
self.display(self.current)

def degrees(self):
self.result = False
self.current = math.degrees(float(txtDisplay.get()))
self.display(self.current)

def log2(self):
self.result = False
self.current = math.log2(float(txtDisplay.get()))
self.display(self.current)

def log10(self):
self.result = False
self.current = math.log10(float(txtDisplay.get()))
self.display(self.current)

def log1p(self):
self.result = False
self.current = math.log1p(float(txtDisplay.get()))
self.display(self.current)

Explanation:
In this code section, we used the class to add various functions. At first, we defined
the class with the name Calc() and then defined all the functions that we want in
want in our Scientific Calculator in Python in the form of a Python function. Apart
from that, we have also defined the function to handle the input number entered by
the user. Also, to check if the function is valid or not we have defined a separate
function in this class. We have included almost all the important functions that are in
a normal scientific calculator. In this, we have made use of a math library and various
built-in functions in that library. These functions are called when the button relating
to it is clicked by the user. The logic of the function is made using the functions
provided by the math library.

To display the text

added_value = Calc()

txtDisplay = Entry(calc, font=('Helvetica',20,'bold'),


bg='black',fg='red',
bd=30,width=28,justify=RIGHT)
txtDisplay.grid(row=0,column=0, columnspan=4, pady=1)
txtDisplay.insert(0,"0")

Explanation:
In this code block, we have defined a variable to store the Calc() class in it. On top of
that, in order to display the text box, wherein the user can see the entered values and
functions, we have added a text box and customized it according to our needs. To
set the size of the textbox we made use of width. Here bd stands for border. We
changed the fonts, background, and alignment of the text. We also used the grid()
function of the Tkinter library to set its position in a proper way.

Adding and Arranging the numbers

numberpad = "789456123"
i=0
btn = []
for j in range(2,5):
for k in range(3):
btn.append(Button(calc, width=6, height=2,
bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,text=numberpad[i]))
btn[i].grid(row=j, column= k, pady = 1)
btn[i]["command"]=lambda x=numberpad[i]:added_value.numberEnter(x
i+=1

Explanation:
Here, in this part of Scientific Calculator in Python, we have defined a variable named
“numberpad” that stores all the digits. Now in order to make a separate box for each
of the digits, we made use of for loop. This loop helps us to create 9 boxes for 9
digits that will be of the same size and font. Using the for loop helps us to eradicate
the need of writing the code 9 times to display the boxes.

Buttons to handle the Clear and Clear all operation

btnClear = Button(calc, text=chr(67),width=6,


height=2,bg='powder blue',
font=('Helvetica',20,'bold')
,bd=4, command=added_value.Clear_Entry
).grid(row=1, column= 0, pady = 1)

btnAllClear = Button(calc, text=chr(67)+chr(69),


width=6, height=2,
bg='powder blue',
font=('Helvetica',20,'bold'),
bd=4,
command=added_value.All_Clear_Entry
).grid(row=1, column= 1, pady = 1)

Explanation:
In this part of the code for Scientific Calculator in Python, the two buttons help the
user to handle the operation like clearing a digit or a function. The buttons for Clear
All clear everything that is added in the textbox. In this also we have customized the
buttons according to our needs.

Buttons for all operations of the Standard Calculator

btnsq = Button(calc, text="\u221A",width=6, height=2,


bg='powder blue', font=('Helvetica',
20,'bold'),
bd=4,command=added_value.squared
).grid(row=1, column= 2, pady = 1)

btnAdd = Button(calc, text="+",width=6, height=2,


bg='powder blue',
font=('Helvetica',20,'bold'),
bd=4,command=lambda:added_value.operation("add")
).grid(row=1, column= 3, pady = 1)

btnSub = Button(calc, text="-",width=6,


height=2,bg='powder blue',
font=('Helvetica',20,'bold'),
bd=4,command=lambda:added_value.operation("sub")
).grid(row=2, column= 3, pady = 1)

btnMul = Button(calc, text="x",width=6,


height=2,bg='powder blue',
font=('Helvetica',20,'bold'),
bd=4,command=lambda:added_value.operation("multi")
).grid(row=3, column= 3, pady = 1)

btnDiv = Button(calc, text="/",width=6,


height=2,bg='powder blue',
font=('Helvetica',20,'bold'),
bd=4,command=lambda:added_value.operation("divide")
).grid(row=4, column= 3, pady = 1)

btnZero = Button(calc, text="0",width=6,


height=2,bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,command=lambda:added_value.numberEnter(0)
).grid(row=5, column= 0, pady = 1)

btnDot = Button(calc, text=".",width=6,


height=2,bg='powder blue',
font=('Helvetica',20,'bold'),
bd=4,command=lambda:added_value.numberEnter(".")
).grid(row=5, column= 1, pady = 1)
btnPM = Button(calc, text=chr(177),width=6,
height=2,bg='powder blue', font=('Helvetica',20,'bold'),
bd=4,command=added_value.mathPM
).grid(row=5, column= 2, pady = 1)

btnEquals = Button(calc, text="=",width=6,


height=2,bg='powder blue',
font=('Helvetica',20,'bold'),
bd=4,command=added_value.sum_of_total
).grid(row=5, column= 3, pady = 1)

Explanation:
These above variables are for the buttons that are for performing various operations
like Multiply, Divide, Subtract, Add etc. These buttons when clicked, call the
respective function that is attached to them, thus helping the user in performing the
desired operation easily. For the design purpose, we made use of all the properties
that are provided by the Button function of the Tkinter library. On top of that, a grid()
function is also used somewhere.

Buttons for Scientific Calculator – Row 1

btnPi = Button(calc, text="pi",width=6,


height=2,bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,command=added_value.pi
).grid(row=1, column= 4, pady = 1)

btnCos = Button(calc, text="Cos",width=6,


height=2,bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,command=added_value.cos
).grid(row=1, column= 5, pady = 1)

btntan = Button(calc, text="tan",width=6,


height=2,bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,command=added_value.tan
).grid(row=1, column= 6, pady = 1)

btnsin = Button(calc, text="sin",width=6,


height=2,bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,command=added_value.sin
).grid(row=1, column= 7, pady = 1)

Explanation:
In this row, we have added the buttons for the functions of Pi, sin, cos, and tan. This
same pattern goes on for the other 4 rows. Also, we have added the functions along
with the respective buttons.

Buttons for Scientific Calculator – Row 2

btn2Pi = Button(calc, text="2pi",width=6,


height=2,bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,command=added_value.tau
).grid(row=2, column= 4, pady = 1)
btnCosh = Button(calc, text="Cosh",width=6,
height=2,bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,command=added_value.cosh
).grid(row=2, column= 5, pady = 1)

btntanh = Button(calc, text="tanh",width=6,


height=2,bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,command=added_value.tanh
).grid(row=2, column= 6, pady = 1)

btnsinh = Button(calc, text="sinh",width=6,


height=2,bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,command=added_value.sinh
).grid(row=2, column= 7, pady = 1)

Buttons for Scientific Calculator – Row 3

btnlog = Button(calc, text="log",width=6,


height=2,bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,command=added_value.log
).grid(row=3, column= 4, pady = 1)

btnExp = Button(calc, text="exp",width=6, height=2,


bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,command=added_value.exp
).grid(row=3, column= 5, pady = 1)

btnMod = Button(calc, text="Mod",width=6,


height=2,bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,command=lambda:added_value.operation("mod")
).grid(row=3, column= 6, pady = 1)

btnE = Button(calc, text="e",width=6,


height=2,bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,command=added_value.e
).grid(row=3, column= 7, pady = 1)

Buttons for Scientific Calculator – Row 4

btnlog10 = Button(calc, text="log10",width=6,


height=2,bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,command=added_value.log10
).grid(row=4, column= 4, pady = 1)

btncos = Button(calc, text="log1p",width=6,


height=2,bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,command=added_value.log1p
).grid(row=4, column= 5, pady = 1)

btnexpm1 = Button(calc, text="expm1",width=6,


height=2,bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd = 4,command=added_value.expm1
).grid(row=4, column= 6, pady = 1)

btngamma = Button(calc, text="gamma",width=6,


height=2,bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,command=added_value.lgamma
).grid(row=4, column= 7, pady = 1)

Buttons for Scientific Calculator – Row 5

btnlog2 = Button(calc, text="log2",width=6,


height=2,bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,command=added_value.log2
).grid(row=5, column= 4, pady = 1)

btndeg = Button(calc, text="deg",width=6,


height=2,bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,command=added_value.degrees
).grid(row=5, column= 5, pady = 1)

btnacosh = Button(calc, text="acosh",width=6,


height=2,bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,command=added_value.acosh
).grid(row=5, column= 6, pady = 1)

btnasinh = Button(calc, text="asinh",width=6,


height=2,bg='black',fg='red',
font=('Helvetica',20,'bold'),
bd=4,command=added_value.asinh
).grid(row=5, column= 7, pady = 1)

lblDisplay = Label(calc, text = "Scientific Calculator",


font=('Helvetica',30,'bold'),
bg='black',fg='red',justify=CENTER)

lblDisplay.grid(row=0, column= 4,columnspan=4)

Menu Bar Options

def iExit():
iExit = tkinter.messagebox.askyesno("Scientific Calculator",
"Do you want to exit ?")
if iExit>0:
root.destroy()
return

def Scientific():
root.resizable(width=False, height=False)
root.geometry("944x568+0+0")

def Standard():
root.resizable(width=False, height=False)
root.geometry("480x568+0+0")

menubar = Menu(calc)

Explanation:
In this section, we have the code to make up the Menubar. This will simply come on
top of the calculator. We have added multiple options like File and Edit. Moreover, to
handle the opening and closing of the Scientific calc window we have defined two
new functions namely Standard() and Scientific(). Inside these functions, we have
used the resizable and geometry functions of the Tkinter library.

Sub-options in Menu Bar

filemenu = Menu(menubar, tearoff = 0)


menubar.add_cascade(label = 'File', menu = filemenu)
filemenu.add_command(label = "Standard", command = Standard)
filemenu.add_command(label = "Scientific", command = Scientific)
filemenu.add_separator()
filemenu.add_command(label = "Exit", command = iExit)

editmenu = Menu(menubar, tearoff = 0)


menubar.add_cascade(label = 'Edit', menu = editmenu)
editmenu.add_command(label = "Cut")
editmenu.add_command(label = "Copy")
editmenu.add_separator()
editmenu.add_command(label = "Paste")

root.config(menu=menubar)

root.mainloop()

Explanation:
Talking about the sub-options in the “File” button there is a feature to switch between
“Standard” and “Scientific” Calculator. Inside the “Edit” button there is Copy, Paste
andCut option. These options will help to copy the answers, paste other values in this
calc and also cut the answer. Whenever the user will click on the Scientific calculator,
a window beside the Standard Calc will open up. A separate window helps a user to
close and access Scientific calc with more use and thus we decided to code in such
a way.

Output for GUI Scientific Calculator in Python


To Switch from Standard to Scientific Calculator

Complete Code for GUI Scientific Calculator in


Python in Tkinter

1 from tkinter import *


2 import math
3 import tkinter.messagebox
4
5 root = Tk()
6 root.title("Scientific Calculator")
7 root.configure(background = 'red')
8 root.resizable(width=False, height=False)
9 root.geometry("480x568+450+90")
10 calc = Frame(root)
11 calc.grid()
12
13 class Calc():
14 def __init__(self):
15 self.total=0
16 self.current=''
17 self.input_value=True
18 self.check_sum=False
19 self.op=''
20 self.result=False
21
22 def numberEnter(self, num):
23 self.result=False
24 firstnum=txtDisplay.get()
25 secondnum=str(num)
26 if self.input_value:
27 self.current = secondnum
28 self.input_value=False
29 else:
30 if secondnum == '.':
31 if secondnum in firstnum:
32 return
33 self.current = firstnum+secondnum
34 self.display(self.current)
35
36 def sum_of_total(self):
37 self.result=True
38 self.current=float(self.current)
39 if self.check_sum==True:
40 self.valid_function()
41 else:
42 self.total=float(txtDisplay.get())
43
44 def display(self, value):
45 txtDisplay.delete(0, END)
46 txtDisplay.insert(0, value)
47
48 def valid_function(self):
49 if self.op == "add":
50 self.total += self.current
51 if self.op == "sub":
52 self.total -= self.current
53 if self.op == "multi":
54 self.total *= self.current
55 if self.op == "divide":
56 self.total /= self.current
57 if self.op == "mod":
58 self.total %= self.current
59 self.input_value=True
60 self.check_sum=False
61 self.display(self.total)
62
63 def operation(self, op):
64 self.current = float(self.current)
65 if self.check_sum:
66 self.valid_function()
67 elif not self.result:
68 self.total=self.current
69 self.input_value=True
70 self.check_sum=True
71 self.op=op
72 self.result=False
73
74 def Clear_Entry(self):
75 self.result = False
76 self.current = "0"
77 self.display(0)
78 self.input_value=True
79
80 def All_Clear_Entry(self):
81 self.Clear_Entry()
82 self.total=0
83
84 def pi(self):
85 self.result = False
86 self.current = math.pi
87 self.display(self.current)
88
89 def tau(self):
90 self.result = False
91 self.current = math.tau
92 self.display(self.current)
93
94 def e(self):
95 self.result = False
96 self.current = math.e
97 self.display(self.current)
98
99 def mathPM(self):
100 self.result = False
101 self.current = -(float(txtDisplay.get()))
102 self.display(self.current)
103
104 def squared(self):
105 self.result = False
106 self.current = math.sqrt(float(txtDisplay.get()))
107 self.display(self.current)
108
109 def cos(self):
110 self.result = False
111 self.current = math.cos(math.radians(float(txtDisplay.get())))
112 self.display(self.current)
113
114 def cosh(self):
115 self.result = False
116 self.current = math.cosh(math.radians(float(txtDisplay.get())))
117 self.display(self.current)
118
119 def tan(self):
120 self.result = False
121 self.current = math.tan(math.radians(float(txtDisplay.get())))
122 self.display(self.current)
123
124 def tanh(self):
125 self.result = False
126 self.current = math.tanh(math.radians(float(txtDisplay.get())))
127 self.display(self.current)
128
129 def sin(self):
130 self.result = False
131 self.current = math.sin(math.radians(float(txtDisplay.get())))
132 self.display(self.current)
133
134 def sinh(self):
135 self.result = False
136 self.current = math.sinh(math.radians(float(txtDisplay.get())))
137 self.display(self.current)
138
139 def log(self):
140 self.result = False
141 self.current = math.log(float(txtDisplay.get()))
142 self.display(self.current)
143
144 def exp(self):
145 self.result = False
146 self.current = math.exp(float(txtDisplay.get()))
147 self.display(self.current)
148
149 def acosh(self):
150 self.result = False
151 self.current = math.acosh(float(txtDisplay.get()))
152 self.display(self.current)
153
154 def asinh(self):
155 self.result = False
156 self.current = math.asinh(float(txtDisplay.get()))
157 self.display(self.current)
158
159 def expm1(self):
160 self.result = False
161 self.current = math.expm1(float(txtDisplay.get()))
162 self.display(self.current)
163
164 def lgamma(self):
165 self.result = False
166 self.current = math.lgamma(float(txtDisplay.get()))
167 self.display(self.current)
168
169 def degrees(self):
170 self.result = False
171 self.current = math.degrees(float(txtDisplay.get()))
172 self.display(self.current)
173
174 def log2(self):
175 self.result = False
176 self.current = math.log2(float(txtDisplay.get()))
177 self.display(self.current)
178
179 def log10(self):
180 self.result = False
181 self.current = math.log10(float(txtDisplay.get()))
182 self.display(self.current)
183
184 def log1p(self):
185 self.result = False
186 self.current = math.log1p(float(txtDisplay.get()))
187 self.display(self.current)
188
189 added_value = Calc()
190
191 txtDisplay = Entry(calc, font=('Helvetica',20,'bold'),
192 bg='black',fg='red',
193 bd=30,width=28,justify=RIGHT)
194 txtDisplay.grid(row=0,column=0, columnspan=4, pady=1)
195 txtDisplay.insert(0,"0")
196
197 numberpad = "789456123"
198 i=0
199 btn = []
200 for j in range(2,5):
201 for k in range(3):
202 btn.append(Button(calc, width=6, height=2,
203 bg='black',fg='red',
204 font=('Helvetica',20,'bold'),
205 bd=4,text=numberpad[i]))
206 btn[i].grid(row=j, column= k, pady = 1)
207 btn[i]["command"]=lambda x=numberpad[i]:added_value.numberEnter(x)
208 i+=1
209
210 btnClear = Button(calc, text=chr(67),width=6,
211 height=2,bg='powder blue',
212 font=('Helvetica',20,'bold')
213 ,bd=4, command=added_value.Clear_Entry
214 ).grid(row=1, column= 0, pady = 1)
215
216 btnAllClear = Button(calc, text=chr(67)+chr(69),
217 width=6, height=2,
218 bg='powder blue',
219 font=('Helvetica',20,'bold'),
220 bd=4,
221 command=added_value.All_Clear_Entry
222 ).grid(row=1, column= 1, pady = 1)
223
224 btnsq = Button(calc, text="\u221A",width=6, height=2,
225 bg='powder blue', font=('Helvetica',
226 20,'bold'),
227 bd=4,command=added_value.squared
228 ).grid(row=1, column= 2, pady = 1)
229
230 btnAdd = Button(calc, text="+",width=6, height=2,
231 bg='powder blue',
232 font=('Helvetica',20,'bold'),
233 bd=4,command=lambda:added_value.operation("add")
234 ).grid(row=1, column= 3, pady = 1)
235
236 btnSub = Button(calc, text="-",width=6,
237 height=2,bg='powder blue',
238 font=('Helvetica',20,'bold'),
239 bd=4,command=lambda:added_value.operation("sub")
240 ).grid(row=2, column= 3, pady = 1)
241
242 btnMul = Button(calc, text="x",width=6,
243 height=2,bg='powder blue',
244 font=('Helvetica',20,'bold'),
245 bd=4,command=lambda:added_value.operation("multi")
246 ).grid(row=3, column= 3, pady = 1)
247
248 btnDiv = Button(calc, text="/",width=6,
249 height=2,bg='powder blue',
250 font=('Helvetica',20,'bold'),
251 bd=4,command=lambda:added_value.operation("divide")
252 ).grid(row=4, column= 3, pady = 1)
253
254 btnZero = Button(calc, text="0",width=6,
255 height=2,bg='black',fg='red',
256 font=('Helvetica',20,'bold'),
257 bd=4,command=lambda:added_value.numberEnter(0)
258 ).grid(row=5, column= 0, pady = 1)
259
260 btnDot = Button(calc, text=".",width=6,
261 height=2,bg='powder blue',
262 font=('Helvetica',20,'bold'),
263 bd=4,command=lambda:added_value.numberEnter(".")
264 ).grid(row=5, column= 1, pady = 1)
265 btnPM = Button(calc, text=chr(177),width=6,
266 height=2,bg='powder blue', font=('Helvetica',20,'bold'),
267 bd=4,command=added_value.mathPM
268 ).grid(row=5, column= 2, pady = 1)
269
270 btnEquals = Button(calc, text="=",width=6,
271 height=2,bg='powder blue',
272 font=('Helvetica',20,'bold'),
273 bd=4,command=added_value.sum_of_total
274 ).grid(row=5, column= 3, pady = 1)
275
276
277
278 btnPi = Button(calc, text="pi",width=6,
279 height=2,bg='black',fg='red',
280 font=('Helvetica',20,'bold'),
281 bd=4,command=added_value.pi
282 ).grid(row=1, column= 4, pady = 1)
283
284 btnCos = Button(calc, text="Cos",width=6,
285 height=2,bg='black',fg='red',
286 font=('Helvetica',20,'bold'),
287 bd=4,command=added_value.cos
288 ).grid(row=1, column= 5, pady = 1)
289
290 btntan = Button(calc, text="tan",width=6,
291 height=2,bg='black',fg='red',
292 font=('Helvetica',20,'bold'),
293 bd=4,command=added_value.tan
294 ).grid(row=1, column= 6, pady = 1)
295
296 btnsin = Button(calc, text="sin",width=6,
297 height=2,bg='black',fg='red',
298 font=('Helvetica',20,'bold'),
299 bd=4,command=added_value.sin
300 ).grid(row=1, column= 7, pady = 1)
301
302 btn2Pi = Button(calc, text="2pi",width=6,
303 height=2,bg='black',fg='red',
304 font=('Helvetica',20,'bold'),
305 bd=4,command=added_value.tau
306 ).grid(row=2, column= 4, pady = 1)
307
308 btnCosh = Button(calc, text="Cosh",width=6,
309 height=2,bg='black',fg='red',
310 font=('Helvetica',20,'bold'),
311 bd=4,command=added_value.cosh
312 ).grid(row=2, column= 5, pady = 1)
313
314 btntanh = Button(calc, text="tanh",width=6,
315 height=2,bg='black',fg='red',
316 font=('Helvetica',20,'bold'),
317 bd=4,command=added_value.tanh
318 ).grid(row=2, column= 6, pady = 1)
319
320 btnsinh = Button(calc, text="sinh",width=6,
321 height=2,bg='black',fg='red',
322 font=('Helvetica',20,'bold'),
323 bd=4,command=added_value.sinh
324 ).grid(row=2, column= 7, pady = 1)
325
326 btnlog = Button(calc, text="log",width=6,
327 height=2,bg='black',fg='red',
328 font=('Helvetica',20,'bold'),
329 bd=4,command=added_value.log
330 ).grid(row=3, column= 4, pady = 1)
331
332 btnExp = Button(calc, text="exp",width=6, height=2,
333 bg='black',fg='red',
334 font=('Helvetica',20,'bold'),
335 bd=4,command=added_value.exp
336 ).grid(row=3, column= 5, pady = 1)
337
338 btnMod = Button(calc, text="Mod",width=6,
339 height=2,bg='black',fg='red',
340 font=('Helvetica',20,'bold'),
341 bd=4,command=lambda:added_value.operation("mod")
342 ).grid(row=3, column= 6, pady = 1)
343
344 btnE = Button(calc, text="e",width=6,
345 height=2,bg='black',fg='red',
346 font=('Helvetica',20,'bold'),
347 bd=4,command=added_value.e
348 ).grid(row=3, column= 7, pady = 1)
349
350
351 btnlog10 = Button(calc, text="log10",width=6,
352 height=2,bg='black',fg='red',
353 font=('Helvetica',20,'bold'),
354 bd=4,command=added_value.log10
355 ).grid(row=4, column= 4, pady = 1)
356
357 btncos = Button(calc, text="log1p",width=6,
358 height=2,bg='black',fg='red',
359 font=('Helvetica',20,'bold'),
360 bd=4,command=added_value.log1p
361 ).grid(row=4, column= 5, pady = 1)
362
363 btnexpm1 = Button(calc, text="expm1",width=6,
364 height=2,bg='black',fg='red',
365 font=('Helvetica',20,'bold'),
366 bd = 4,command=added_value.expm1
367 ).grid(row=4, column= 6, pady = 1)
368
369 btngamma = Button(calc, text="gamma",width=6,
370 height=2,bg='black',fg='red',
371 font=('Helvetica',20,'bold'),
372 bd=4,command=added_value.lgamma
373 ).grid(row=4, column= 7, pady = 1)
374
375 btnlog2 = Button(calc, text="log2",width=6,
376 height=2,bg='black',fg='red',
377 font=('Helvetica',20,'bold'),
378 bd=4,command=added_value.log2
379 ).grid(row=5, column= 4, pady = 1)
380
381 btndeg = Button(calc, text="deg",width=6,
382 height=2,bg='black',fg='red',
383 font=('Helvetica',20,'bold'),
384 bd=4,command=added_value.degrees
385 ).grid(row=5, column= 5, pady = 1)
386
387 btnacosh = Button(calc, text="acosh",width=6,
388 height=2,bg='black',fg='red',
389 font=('Helvetica',20,'bold'),
390 bd=4,command=added_value.acosh
391 ).grid(row=5, column= 6, pady = 1)
392
393 btnasinh = Button(calc, text="asinh",width=6,
394 height=2,bg='black',fg='red',
395 font=('Helvetica',20,'bold'),
396 bd=4,command=added_value.asinh
397 ).grid(row=5, column= 7, pady = 1)
398
399 lblDisplay = Label(calc, text = "Scientific Calculator",
400 font=('Helvetica',30,'bold'),
401 bg='black',fg='red',justify=CENTER)
402
403 lblDisplay.grid(row=0, column= 4,columnspan=4)
404
405 def iExit():
406 iExit = tkinter.messagebox.askyesno("Scientific Calculator",
407 "Do you want to exit ?")
408 if iExit>0:
409 root.destroy()
410 return
411
412 def Scientific():
413 root.resizable(width=False, height=False)
414 root.geometry("944x568+0+0")
415
416
417 def Standard():
418 root.resizable(width=False, height=False)
419 root.geometry("480x568+0+0")
420
421 menubar = Menu(calc)
422
423 filemenu = Menu(menubar, tearoff = 0)
424 menubar.add_cascade(label = 'File', menu = filemenu)
425 filemenu.add_command(label = "Standard", command = Standard)
426 filemenu.add_command(label = "Scientific", command = Scientific)
427 filemenu.add_separator()
428 filemenu.add_command(label = "Exit", command = iExit)
429
430
431 editmenu = Menu(menubar, tearoff = 0)
432 menubar.add_cascade(label = 'Edit', menu = editmenu)
433 editmenu.add_command(label = "Cut")
434 editmenu.add_command(label = "Copy")
435 editmenu.add_separator()
436 editmenu.add_command(label = "Paste")
437
438 root.config(menu=menubar)
439

YouTube Reference Tutorial Link


How to Create Scientific Calculator in Python - Full Tutorial

Official Library Links

Math library: Official Documentation Link


Tkinter library: Official Documentation Link

Endnote

Finally! Here’s the end of our article on Scientific Calculator in Python using Tkinter.
We really hope that this article turns out to be a great source of help to you. We tried
our best to explain each and every concept involved in this tutorial. We at
CopyAssignments firmly believe that developing projects is the only way of being a
pioneer of Python. In this GUI Scientific Calculator in Python project we have added
some basic to intermediate functions, now it is your turn to add advanced functions
and upgrade the project to the next level. We will soon be back with one another
tutorial, till then keep Learning, Executing, and Building. Thank you for visiting our
website.

Best 100+ Python Projects with source code

Also Read:

Most Underrated Database Python List Methods Top 5 Free HTML Resume
Trick | Life-Saving SQL Templates in 2024 | With
Command Source Code

How to See Connected Wi- 2023 Merry Christmas 23 AI Tools You Won’t
Fi Passwords in Windows? using Python Turtle Believe are Free

Python 3.12.1 is Now Best Deepfake Apps and Amazon launched free
Available Websites You Can Try for Prompt Engineering course:
Fun Enroll Now

10 GitHub Repositories to Hello World in 35 How to Scrape Data From


Master Machine Learning Programming Languages Any Website with Python?

Become Job Ready With Free Python Certification Download 1000+ Projects,
Free Harvard Computer course from Alison: Good All B.Tech & Programming
Science course: Enroll Now for Resume Notes, Job, Resume &
Interview Guide, and More
– Get Your Ultimate
Programming Bundle!

Udacity Giving Free Python Love Babbar’s Income Top 5 Websites to Learn
Course: Here is how to Revealed Programming in 2024
Enroll

Python Internship for Microsoft Giving Free Top 5 Free Python Courses
college students and Python Course in 2023: on YouTube in 2024
freshers: Apply Here Enroll Now

Complete Python Roadmap New secrets to Earn money Connect with HR Directly –
for Beginners in 2024 with Python in 2024 Job Hack

Google offering free Python What is an AI Tool? Google Internship 2024


course: Enroll Today

TCS Launched Free Top Free AI Tools for Unveiling the Future of AI
Certification Course with Students and Job Seekers Detector
Industry Recognized Value

Share:       

Author: Ayush Purawr

← GUI Tic Tac Toe game in Java Word counter in Java →

© Copyright 2019-2024 www.copyassignment.com. All rights reserved. Developed by copyassignment

You might also like