Skip to content
This repository was archived by the owner on Dec 22, 2023. It is now read-only.

Commit a9acc62

Browse files
author
Lavish Bansal
committed
Comments Added
1 parent 0af0562 commit a9acc62

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

Scripts/Miscellaneous/Scientific_Calculator_GUI/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ The Calculator is built in such a way that it first allows the user to enter the
66
**Note:** Put Proper Paranthesis while writing the complete expression in Calculator.
77

88
## Modules Required
9-
Tkinter
10-
Python3
9+
Python3
10+
(No external library or module needed)
1111

1212
## How To Open
1313
Simply open the python file, Scientific_Calculator.py

Scripts/Miscellaneous/Scientific_Calculator_GUI/Scientific_Calculator.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
#import Gui Package and libraries
12
import tkinter.font
23
from tkinter import *
34
import math
45

6+
57
def clearall():
8+
9+
'''Clear function toclear the screen
10+
and reset all variables'''
11+
612
global expression
713
global equation
814
global value
@@ -13,9 +19,14 @@ def clearall():
1319
equation.set(expression)
1420

1521
def sgn(a):
22+
#Signum function
1623
return 1 if a>0 else -1 if a<0 else 0
1724

1825
def clearback():
26+
27+
'''Backspace button function to delete
28+
a character from the screen'''
29+
1930
result1=""
2031
result2=""
2132
global equation
@@ -91,6 +102,12 @@ def clearback():
91102
except:pass
92103

93104
def pressbtn(num):
105+
106+
'''Function to determine which button is pressed.
107+
Everytime a button a pressed , this function is
108+
called and a parameter is passed, which updates the
109+
variables and the expression to be evaluated'''
110+
94111
global expression
95112
global value
96113
global ans
@@ -137,6 +154,10 @@ def pressbtn(num):
137154
elif num=='e^':value += 'math.e**'
138155

139156
def equal():
157+
158+
'''On pressing equal to button, this function is called.
159+
And it prints the result on the screen.'''
160+
140161
global ans
141162
global value
142163
global expression
@@ -149,6 +170,7 @@ def equal():
149170
value=''
150171
expression=''
151172

173+
#Configuring the layout of Calculator
152174
root=Tk()
153175
root.title("Scientific Calculator")
154176

@@ -163,18 +185,21 @@ def equal():
163185
area.insert(0,"0")
164186
area.grid(row=0,columnspan=8)
165187

188+
#standard calculator
166189
def standard():
167190
root.geometry('361x350')
168191
area['width']=28
169192
area.grid(row=0,columnspan=4,sticky= EW)
170193
root.title("Standard Calculator")
171-
194+
195+
#scientific calculator
172196
def scientific():
173197
root.geometry('742x350')
174198
area['width']=60
175199
area.grid(row=0,columnspan=8)
176200
root.title("Scientific Calculator")
177201

202+
# adding menubar on top
178203
menubar = Menu(cal)
179204
filemenu= Menu(menubar,tearoff=0)
180205
menubar.add_cascade(label="File", menu=filemenu)
@@ -187,6 +212,7 @@ def scientific():
187212
ans=""
188213
expression=""
189214

215+
#Fonts and Colours
190216
font= tkinter.font.Font(size=12,weight= "bold", family='Helvetica',)
191217
h=2
192218
w=7
@@ -200,14 +226,17 @@ def scientific():
200226

201227
numberpad = [7,8,9,4,5,6,1,2,3]
202228
i=0
229+
203230
for j in range(3):
204231
for k in range(3):
205232
Button(cal,command = lambda x = str(numberpad[i]) : pressbtn(x), text = str(numberpad[i]), bg= bg1, fg=fg2,activebackground=actvbgnd,
206233
height=h, width=w,font= font).grid(row=j+2,column=k)
207234
i+=1
208235

209-
r=5
210-
c=7
236+
r=5 #number of rows
237+
c=7 #number of columns
238+
239+
#creating buttons
211240
Button(cal,command = lambda: pressbtn(0), text = "0", bg= bg1, fg=fg2,activebackground=actvbgnd,
212241
height=h, width=w,font= font).grid(row=r,column= c-7)
213242
Button(cal,command = lambda: pressbtn('00'),text = "00", bg= bg1, fg=fg2,activebackground=actvbgnd,
@@ -238,6 +267,7 @@ def scientific():
238267
height=h,width=w,font= font).grid(row=j+1,column=k+4)
239268
i+=1
240269

270+
#set the spacing between buttons
241271
msize=60
242272
cal.rowconfigure(0,minsize=50)
243273
for i in range(1,6):
@@ -247,4 +277,4 @@ def scientific():
247277
for i in range(8):
248278
cal.columnconfigure(i,minsize= msize)
249279

250-
cal.mainloop()
280+
cal.mainloop()

0 commit comments

Comments
 (0)