You are on page 1of 20

SESSION-2019-20

INVESTIGATORY PROJCET
TOPIC- BUILDING A SIMPLE
AND GUI

CALCULATOR

SUBMITTED BY
SUBMITTED TO
SUMIT CHAUHAN MR.
AMIT GUPTA

ACKNOWLEDGEMEN
T ACKNOWLEDGEMENT

I would like to express a deep sense of thanks & gratitude to


my
Project guide Mr AMIT GUPTA SIR for guiding me
immensely through the course of the project. He always
evinced keen interest in my work. His constructive advice &
constant motivation have been responsible for the successful
completion of this project.
I also thanks to my parents for their motivation &
support. I must thanks to my class mates for their timely help
& support for completion of this project.
Last but not the least I would like to thanks all those
who had helped directly and indirectly towards the
completion of this project.
ROLL.NO-
25607340
Class :XII (B)

CERTIFICATE

The project report entitled “simple and GUI


CALCULATOR ” Submitted by SUMIT CHAUHAN
of class XII Science for the CBSE Senior Secondary
Examination 2019-20, Class XII for Computer Science
at ……………………………………………………….
has been examined.
SIGNATURE OF EXAMINER

TOOLS/PLATFORM, LANGUAGE
TO BE USED
Software and hardware specification as the name suggests, tells us about the

various characteristics of the software and the hardware environment used i.e.

the development environment used. Here I specify various software languages,

supporting tools that have been used for the development of the system. These

tools and the languages have been used because of their relative ease of

understand and personal interest of the team developing the project.

SOFTWARE ENVIRONMENT
OF PROJECT

PLATFORM WINDOWS 10

FRONT END IDE PYTON(3.7)


BACK END MICROSOFT
WORD

SOFTWARE LANGUAGES USED

In the development of a project the selection of an appropriate programming


language and a platform is of primary importance. The major part of credit of
success of a project goes to the software environment chosen by the developer.
Selecting a language from the ocean of the languages is very difficult. A
developer has to consider the various features and functionalities that a
particular language can provide him/her how easily and successfully the
requirements of a user can be fulfilled depend on the s/w language chosen.
More over the developer also has to take care of the various facilities, he can
use. In the development of this application, it has been taken into great
consideration that server overhead should be low as far as possible.

PYTHON
Python is one of the most dynamic and versatile programming languages
available in the industry today. Since its inception in the 1990s, Python has
become hugely popular and even today there are thousands who are learning
this Object-Oriented Programming language. If you are new to the world of
programming, you have already heard the buzz it has created in recent times
because of the features of Python and must be wondering what makes this
programming language special.

python is an object-oriented programming language that is designed in C. By


nature, it is a high-level programming language that allows for the creation of
both simple as well as complex operations. Along with this Python comes
inbuilt with a wide array of modules as well as libraries which allows it to
support many different programming languages like Java, C, C++, and JSON.

Features of Python
As a programming language, the features of Python brought to the table are
many. Some of the most significant features of Python are:

 Features of Python – easy to Code


Python is a very developer-friendly language which means that anyone and
everyone can learn to code it in a couple of hours or days. As compared to
other object-oriented programming languages like Java, C, C++, and C#, Python
is one of the easiest to learn.

 Open Source and Free


Python is an open-source programming language which means that anyone can
create and contribute to its development. Python has an online forum where
thousands of coders gather daily to improve this language further. Along with
this Python is free to download and use in any operating system, be it Windows,
Mac or Linux.

 Course Curriculum
Python Certification Training for Data Science

Instructor-led Live SessionsReal-life Case StudiesAssignmentsLifetime Access

Support for GUI

GUI or Graphical User Interface is one of the key aspects of any programming
language because it has the ability to add flair to code and make the results
more visual. Python has support for a wide array of GUIs which can easily be
imported to the interpreter, thus making this one of the most favorite languages
for developers.

 Object-Oriented Approach
One of the key aspects of Python is its object-oriented approach. This basically
means that Python recognizes the concept of class and object encapsulation thus
allowing programs to be efficient in the long run.
 High-Level Language
Python has been designed to be a high-level programming language, which
means that when you code in Python you don’t need to be aware of the coding
structure, architecture as well as memory management.

 Integrated by Nature
Python is an integrated language by nature. This means that the python
interpreter executes codes one line at a time. Unlike other object-oriented
programming languages, we don’t need to compile Python code thus making the
debugging process much easier and efficient. Another advantage of this is, that
upon execution the Python code is immediately converted into an intermediate
form also known as byte-code which makes it easier to execute and also saves
runtime in the long run.

 Highly Portable
Suppose you are running Python on Windows and you need to shift the same to
either a Mac or a Linux system, then you can easily achieve the same in Python
without having to worry about changing the code. This is not possible in other
programming languages, thus making Python one of the most portable
languages available in the industry.

Python offers multiple options for developing GUI (Graphical User


Interface). Out of all the GUI methods, tkinter is most commonly used
method. It is a standard Python interface to the Tk GUI toolkit shipped
with Python. Python with tkinter outputs the fastest and easiest way to
create the GUI applications. Creating a GUI using tkinter is an easy task.
To create a tkinter :
1. Importing the module – tkinter
2. Create the main window (container)
3. Add any number of widgets to the main window
4. Apply the event Trigger on the widgets.
# main python proghram

response=['Welcome to smart calculator','My name is sumit',

'Thanks for enjoy with me ','Sorry ,this is beyond my ability']

# fetching tokens from the text command

def extract_from_text(text):

l=[]

for t in text.split(' '):

try:

l.append(float(t))

except ValueError:

pass

return l

# calculating LCM

def lcm(a,b):

L=a if a>b else b

while L<=a*b:

if L%a==0 and L%b==0:

return L

L+=1
# calculating HCF

def hcf(a,b):

H=a if a<b else b

while H>=1:

if a%H==0 and b%H==0:

return H

H-=1

# Addition

def add(a,b):

return a+b

# Subtraction

def sub(a,b):

return a-b

# Multiplication

def mul(a,b):

return a*b

# Division

def div(a,b):

return a/b
# Remainder

def mod(a,b):

return a%b

# Response to command

# printing - "Thanks for enjoy with me" on exit

def end():

print(response[2])

input('press enter key to exit')

exit()

def myname():

print(response[1])

def sorry():

print(response[3])

# Operations - performed on the basis of text tokens

operations={'ADD':add,'PLUS':add,'SUM':add,'ADDITION':add,

'SUB':sub,'SUBTRACT':sub, 'MINUS':sub,

'DIFFERENCE':sub,'LCM':lcm,'HCF':hcf,

'PRODUCT':mul,
'MULTIPLY':mul,'MULTIPLICATION':mul,

'DIVISION':div,'MOD':mod,'REMANDER'

:mod,'MODULAS':mod}
# commands

commands={'NAME':myname,'EXIT':end,'END':end,'CLOSE':end}

print('--------------'+response[0]+'------------')

print('--------------'+response[1]+'--------------------')

while True:

print()

text=input('enter your queries: ')

for word in text.split(' '):

if word.upper() in operations.keys():

try:

l = extract_from_text(text)

r = operations[word.upper()] (l[0],l[1])

print(r)

except:

print('something went wrong going plz enter again


!!')

finally:

break

elif word.upper() in commands.keys():

commands[word.upper()]()

break
else:

sorry()

OUTPUT

# calculator using Tkinter

# import everything from tkinter module

from tkinter import *

# globally declare the expression variable

expression = ""

# Function to update expressiom

# in the text entry box


def press(num):

# point out the global expression variable

global expression

# concatenation of string

expression = expression + str(num)

# update the expression by using set method

equation.set(expression)

# Function to evaluate the final expression

def equalpress():

# Try and except statement is used

# for handling the errors like zero

# division error etc.

# Put that code inside the try block

# which may generate the error

try:

global expression

# eval function evaluate the expression


# and str function convert the result

# into string

total = str(eval(expression))

equation.set(total)

# initialze the expression variable

# by empty string

expression = ""

# if error is generate then handle

# by the except block

except:

equation.set(" error ")

expression = ""

# Function to clear the contents

# of text entry box

def clear():

global expression

expression = ""

equation.set("")
# Driver code

if __name__ == "__main__":

# create a GUI window

gui = Tk()

# set the background colour of GUI window

gui.configure(background="light green")

# set the title of GUI window

gui.title("Simple Calculator")

# set the configuration of GUI window

gui.geometry("265x125")

# StringVar() is the variable class

# we create an instance of this class

equation = StringVar()

# create the text entry box for

# showing the expression .

expression_field = Entry(gui, textvariable=equation)


# grid method is used for placing

# the widgets at respective positions

# in table like structure .

expression_field.grid(columnspan=4, ipadx=70)

equation.set('enter your expression')

# create a Buttons and place at a particular

# location inside the root window .

# when user press the button, the command or

# function affiliated to that button is executed .

button1 = Button(gui, text=' 1 ', fg='black', bg='red',

command=lambda: press(1), height=1,


width=7)

button1.grid(row=2, column=0)

button2 = Button(gui, text=' 2 ', fg='black', bg='red',

command=lambda: press(2), height=1,


width=7)

button2.grid(row=2, column=1)

button3 = Button(gui, text=' 3 ', fg='black', bg='red',

command=lambda: press(3), height=1,


width=7)

button3.grid(row=2, column=2)
button4 = Button(gui, text=' 4 ', fg='black', bg='red',

command=lambda: press(4), height=1,


width=7)

button4.grid(row=3, column=0)

button5 = Button(gui, text=' 5 ', fg='black', bg='red',

command=lambda: press(5), height=1,


width=7)

button5.grid(row=3, column=1)

button6 = Button(gui, text=' 6 ', fg='black', bg='red',

command=lambda: press(6), height=1,


width=7)

button6.grid(row=3, column=2)

button7 = Button(gui, text=' 7 ', fg='black', bg='red',

command=lambda: press(7), height=1,


width=7)

button7.grid(row=4, column=0)

button8 = Button(gui, text=' 8 ', fg='black', bg='red',

command=lambda: press(8), height=1,


width=7)

button8.grid(row=4, column=1)
button9 = Button(gui, text=' 9 ', fg='black', bg='red',

command=lambda: press(9), height=1,


width=7)

button9.grid(row=4, column=2)

button0 = Button(gui, text=' 0 ', fg='black', bg='red',

command=lambda: press(0), height=1,


width=7)

button0.grid(row=5, column=0)

plus = Button(gui, text=' + ', fg='black', bg='red',

command=lambda: press("+"), height=1, width=7)

plus.grid(row=2, column=3)

minus = Button(gui, text=' - ', fg='black', bg='red',

command=lambda: press("-"), height=1, width=7)

minus.grid(row=3, column=3)

multiply = Button(gui, text=' * ', fg='black', bg='red',

command=lambda: press("*"), height=1,


width=7)

multiply.grid(row=4, column=3)

divide = Button(gui, text=' / ', fg='black', bg='red',

command=lambda: press("/"), height=1,


width=7)
divide.grid(row=5, column=3)

equal = Button(gui, text=' = ', fg='black', bg='red',

command=equalpress, height=1, width=7)

equal.grid(row=5, column=2)

clear = Button(gui, text='Clear', fg='black', bg='red',

command=clear, height=1, width=7)

clear.grid(row=5, column='1')

# start the GUI

gui.mainloop()

BIBILIOGRAPHY
 w.w.w.google.com
 w.w.w.geeksforgeek.org
 w.w.w.edureka.com

You might also like