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 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 calculator on your screen greatly facilitates completing online projects, especially in these days of online learning. Click here to copy the source code.
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 in this article, we will take you through all the concepts that are important and also provide you with the source code for your reference.
Scientific Calculator in Python: Project Overview
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. |
Language/s Used: | Python |
IDE | Thonny and PyCharm(Recommended) |
Python version (Recommended): | Python 3. x |
Database: | None |
Type: | Desktop Application |
Recommended for | Intermediate Python Programmers |
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 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 click on the numbers they desire for the computations, the user needs only click. As a result, the user of this application can utilize a straightforward calculator.
Features of Scientific Calculator
- All basic operators like addition, multiplication, subtraction, and division.
- Dedicated buttons for sin, cos, tan, and cot.
- Functions for log
- Functions for ratio and exponents.
- Other buttons like Pi, mod, and x!
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
Complete Code for GUI Scientific Calculator in Python in Tkinter
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() 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) 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") 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 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) 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) 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) 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) 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) 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) 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) 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) 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()
YouTube Reference Tutorial Link
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.
Also Read:
- Imagination to Reality, Unlocking the Future: Genesis Physics Engine for 4D Simulation
- Simple Code to compare Speed of Python, Java, and C++?
- Falling Stars Animation on Python.Hub October 2024
- Most Underrated Database Trick | Life-Saving SQL Command
- Python List Methods
- Top 5 Free HTML Resume Templates in 2024 | With Source Code
- How to See Connected Wi-Fi Passwords in Windows?
- 2023 Merry Christmas using Python Turtle
- 23 AI Tools You Won’t Believe are Free
- Python 3.12.1 is Now Available
- Best Deepfake Apps and Websites You Can Try for Fun
- Amazon launched free Prompt Engineering course: Enroll Now
- 10 GitHub Repositories to Master Machine Learning
- Hello World in 35 Programming Languages
- How to Scrape Data From Any Website with Python?
- Become Job Ready With Free Harvard Computer Science course: Enroll Now
- Free Python Certification course from Alison: Good for Resume
- Download 1000+ Projects, All B.Tech & Programming Notes, Job, Resume & Interview Guide, and More – Get Your Ultimate Programming Bundle!
- Udacity Giving Free Python Course: Here is how to Enroll
- Love Babbar’s Income Revealed
- Top 5 Websites to Learn Programming in 2024
- Python Internship for college students and freshers: Apply Here
- Microsoft Giving Free Python Course in 2023: Enroll Now
- Top 5 Free Python Courses on YouTube in 2024
- Complete Python Roadmap for Beginners in 2024
- New secrets to Earn money with Python in 2024
- Connect with HR Directly – Job Hack
- Google offering free Python course: Enroll Today
- What is an AI Tool?
- Google Internship 2024