├── README.md └── calculator.py /README.md: -------------------------------------------------------------------------------- 1 | # GUI-scientific-calculator-using-python 2 | it's a scientific calculator using python.It will consist a graphical user interface using Tkinter libraries in python. 3 | 4 | An advanced Calculator implemented in Python Programming Language using Tkinter Module. 5 | 6 | Project Title : "Scientic-Calculator" 7 | 8 | Operations Available = 1. Addition 9 | 2. Substraction 10 | 3. Division 11 | 4. Multiplication and many more. 12 | 13 | Advantages = 1. Bigger Buttons 14 | 2. Compact and Fast 15 | 3. Lots of functionalities 16 | 4. Attractive GUI 17 | 18 | ------------------------------------BASICS------------------------------------------------ 19 | Python = is a Dynamically Typed, Object Oriented Programming Language 20 | Tkinter = Inbuilt Python module --> to create simple GUI apps. 21 | = Standard Python interface to Tk GUI toolkit. 22 | 23 | Tk = is the toolkit 24 | 25 | mainloop() = Most important function while working with Tkinter. = You must call mainloop only one time. = It is an infinite loop. 26 | 27 | -----------------------------BASIC Code for Tkinter---------------------------------- 28 | from tkinter import * 29 | 30 | root = Tk() # 'root' is object of 'Tk' class 31 | # creates a basic gui 32 | # basic default compoments present in GUI 33 | # A base is created -> for GUI Development # we can create button, menu bar,etc on this base 34 | 35 | root.mainloop() # event loop -> called only once 36 | -------------------------------------------------------------------------------- /calculator.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | 4 | class calculate(): 5 | 6 | def __init__(self): 7 | self.root = Tk() 8 | self.root.title("Calculator") 9 | self.root.geometry("290x260") 10 | 11 | self.root.maxsize(290, 260) 12 | self.root.minsize(290, 260) 13 | self.root.config(bg="grey") 14 | 15 | self.resultwindow = Entry(self.root,borderwidth=5, relief=SUNKEN) 16 | self.resultwindow.grid(row=0,column=0,columnspan=6,pady=5) 17 | self.resultwindow.config(font=("Arial", 18)) 18 | self.resultwindow.focus_set() # Sets focus on the input text area 19 | 20 | # Buttons 21 | self.button1 = Button(self.root, text="1", width=3, command=lambda:self.ins('1'),relief=RAISED,bg='light green') 22 | self.button1.grid(row=1,column=0, padx=3, pady=3) 23 | self.button1.config(font=("Arial", 18)) 24 | 25 | self.button2 = Button(self.root, text="2", width=3, command=lambda:self.ins('2'),relief=RAISED,bg='light green') 26 | self.button2.grid(row=1, column=1, padx=3, pady=3) 27 | self.button2.config(font=("Arial", 18)) 28 | 29 | self.button3 = Button(self.root, text="3", width=3, command=lambda:self.ins('3'),relief=RAISED,bg='light green') 30 | self.button3.grid(row=1, column=2, padx=3, pady=3) 31 | self.button3.config(font=("Arial", 18)) 32 | 33 | self.button4 = Button(self.root, text="4", width=3, command=lambda:self.ins('4'),relief=RAISED,bg='light green') 34 | self.button4.grid(row=2, column=0, padx=3, pady=3) 35 | self.button4.config(font=("Arial", 18)) 36 | 37 | self.button5 = Button(self.root, text="5", width=3, command=lambda:self.ins('5'),relief=RAISED,bg='light green') 38 | self.button5.grid(row=2, column=1, padx=3, pady=3) 39 | self.button5.config(font=("Arial", 18)) 40 | 41 | self.button6 = Button(self.root, text="6", width=3, command=lambda:self.ins('6'),relief=RAISED,bg='light green') 42 | self.button6.grid(row=2, column=2, padx=3, pady=3) 43 | self.button6.config(font=("Arial", 18)) 44 | 45 | self.button7 = Button(self.root, text="7", width=3, command=lambda:self.ins('7'),relief=RAISED,bg='light green') 46 | self.button7.grid(row=3, column=0, padx=3, pady=3) 47 | self.button7.config(font=("Arial", 18)) 48 | 49 | self.button8 = Button(self.root, text="8", width=3, command=lambda:self.ins('8'),relief=RAISED,bg='light green') 50 | self.button8.grid(row=3, column=1, padx=3, pady=3) 51 | self.button8.config(font=("Arial", 18)) 52 | 53 | self.button9 = Button(self.root, text="9", width=3, command=lambda:self.ins('9'),relief=RAISED,bg='light green') 54 | self.button9.grid(row=3, column=2, padx=3, pady=3) 55 | self.button9.config(font=("Arial", 18)) 56 | 57 | self.button0 = Button(self.root, text="0", width=3, command=lambda: self.ins('0'),relief=RAISED,bg='light green') 58 | self.button0.grid(row=4, column=0, padx=3, pady=3) 59 | self.button0.config(font=("Arial", 18)) 60 | 61 | self.button_open = Button(self.root, text="(", width=3, command=lambda: self.ins('('),relief=RAISED) 62 | self.button_open.grid(row=4, column=1, padx=3, pady=3) 63 | self.button_open.config(font=("Arial", 18)) 64 | 65 | self.button_close = Button(self.root, text=")", width=3, command=lambda: self.ins(')'),relief=RAISED) 66 | self.button_close.grid(row=4, column=2, padx=3, pady=3) 67 | self.button_close.config(font=("Arial", 18)) 68 | 69 | # Operations Buttons 70 | 71 | self.buttonplus = Button(self.root, text="+", width=3, command=lambda:self.ins('+'),relief=RAISED) 72 | self.buttonplus.grid(row=1, column=3, padx=3, pady=3) 73 | self.buttonplus.config(font=("Arial", 18)) 74 | 75 | self.buttonminus = Button(self.root, text="-", width=3, command=lambda:self.ins('-'),relief=RAISED) 76 | self.buttonminus.grid(row=1, column=4, padx=3, pady=3) 77 | self.buttonminus.config(font=("Arial", 18)) 78 | 79 | self.buttondivide = Button(self.root, text="/", width=3, command=lambda:self.ins('/'),relief=RAISED) 80 | self.buttondivide.grid(row=2, column=3, padx=3, pady=3) 81 | self.buttondivide.config(font=("Arial", 18)) 82 | 83 | self.buttonmultiply = Button(self.root, text="*", width=3, command=lambda:self.ins('*'),relief=RAISED) 84 | self.buttonmultiply.grid(row=2, column=4, padx=3, pady=3) 85 | self.buttonmultiply.config(font=("Arial", 18)) 86 | 87 | self.buttoncancel = Button(self.root, text="C", width=3, command=lambda: self.cancel(),relief=RAISED,bg='#EF5350',fg='white') 88 | self.buttoncancel.grid(row=3, column=4, padx=3, pady=3) 89 | self.buttoncancel.config(font=("Arial", 18)) 90 | 91 | self.buttondeleteall = Button(self.root, text="Del", width=3, command=lambda: self.delete_all(),relief=RAISED) 92 | self.buttondeleteall.grid(row=3, column=3, padx=3, pady=3) 93 | self.buttondeleteall.config(font=("Arial", 18)) 94 | 95 | self.buttonresult = Button(self.root, text="=", width=7, command=lambda:self.calculate(),relief=RAISED,bg='#FFEE58') 96 | self.buttonresult.grid(row=4, column=3, padx=3, pady=3, columnspan=2) 97 | self.buttonresult.config(font=("Arial", 18)) 98 | 99 | self.root.mainloop() 100 | 101 | def ins(self,val): 102 | self.resultwindow.insert(END, val) 103 | 104 | def cancel(self): 105 | self.resultwindow.delete(0, 'end') 106 | 107 | def delete_all(self): 108 | x = self.resultwindow.get() 109 | self.resultwindow.delete(0, 'end') 110 | y = x[:-1] 111 | self.resultwindow.insert(0, y) 112 | 113 | def calculate(self): 114 | x = self.resultwindow.get() 115 | answer = eval(x) 116 | self.resultwindow.delete(0, 'end') 117 | self.resultwindow.insert(0, answer) 118 | 119 | 120 | if __name__ == "__main__": 121 | calculate() 122 | --------------------------------------------------------------------------------