Oh Snap!

Please turnoff your ad blocking mode for viewing your site content

Hit enter after type your search item

Python Tkinter GUI Script to Make a Advanced Scientific Calculator Desktop App Using Math Module Full Project For Beginners

/
/
/
31 Views

 

Welcome folks today in this folks we will be building a advanced scientific calculator in python using tkinter. All the full source code of the application will be shown below.

 

 

 

Get Started

 

 

In order to get started you need to install the following libraries shown below

 

pip install tkinter

 

pip install math

 

After installing these libraries make an app.py file and copy paste the following code

 

app.py

 

 

from tkinter import Tk
from tkinter import StringVar,Entry,Button
from math import pi,e,sin,cos,tan,log,log10,ceil,degrees,radians,exp,asin,acos,floor


class calculator:
    def __init__(self):
        window=Tk()
        window.title('Scientific Calculator')
        window.configure(background="white")
        self.string=StringVar()
        entry=Entry(window,textvariable=self.string)
        entry.grid(row=0,column=0,columnspan=6)
        entry.configure(background="white")
        entry.focus()
        
        values=["7","8","9","/","%","clear","AC",
                "4","5","6","*","(",")","**",
                "1","2","3","-","=",",","0",".","min","+","sin","asin","cos","acos","tan()",
                "pow","log10","max","abs","floor","pi","e","log","ceil","degrees","radians"]
        text=1
        i=0
        row=1
        col=0
        for txt in values:
            padx=10
            pady=10
            if(i==7):
                row=2
                col=0
            if(i==14):
                row=3
                col=0
            if(i==19):
                row=4
                col=0
            if(i==26):
                row=5
                col=0
            if(i==33):
                row=6
                col=0
            if(txt=='='):
                btn=Button(window,height=2,width=4,padx=70,pady=pady,text=txt,command=lambda txt=txt:self.equals())
                btn.grid(row=row,column=col,columnspan=3,padx=2,pady=2)
                btn.configure(background="yellow")

            elif(txt=='clear'):
                btn=Button(window,height=2,width=4,padx=padx,pady=pady, text=txt ,command=lambda txt=txt:self.delete())
                btn.grid(row=row,column=col,padx=1,pady=1)
                btn.configure(background="grey")
            elif(txt=='AC'):
                btn=Button(window,height=2,width=4,padx=padx,pady=pady,text=txt,command=lambda txt=txt:self.clearall())
                btn.grid(row=row,column=col,padx=1,pady=1)
                btn.configure(background="red")
            else:
                btn=Button(window,height=2,width=4,padx=padx,pady=pady,text=txt ,command=lambda txt=txt:self.addChar(txt))
                btn.grid(row=row,column=col,padx=1,pady=1)
                btn.configure(background="cyan")

            col=col+1
            i=i+1
        window.mainloop()
        

    def clearall(self):
        self.string.set("")

    def equals(self):
        result=""

        try:
            result=eval(self.string.get())
            self.string.set(result)
        except:
            result="INVALID INPUT"
        self.string.set(result)
        
    def addChar(self,char):
        self.string.set(self.string.get()+(str(char)))
        
    def delete(self):
        self.string.set(self.string.get()[0:-1])
           
calculator()

 

READ  Python Tkinter GUI Script to Make a Windows Notepad to Make Notes Full Project For Beginners

 

So now if you execute this python script app.py by typing the below command shown below

 

python app.py

 

 

 

 

 

 

DOWNLOAD SOURCE CODE

 

Leave a Comment

Your email address will not be published. Required fields are marked *

This div height required for enabling the sticky sidebar
Coding Shiksha 2020. All Rights Reserved.
Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views :