0% found this document useful (0 votes)
60 views16 pages

PYTHON Micro Project

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 16

2023

Yash Pawar

4/22/2023
GUI Calculator Using PYTHON.
A Project Report On

“GUI CALCULATOR”

Submitted by:

PAWAR YASH SANJAY [2011630041]


SURAJ MOHAN KHANDARE [2011630064]
PRADIP GOVIND RATHOD [2011630043]
GOPAL MANOJ PADALKAR [2011630049]

Guided By :

Mr. P. H. Gutte

Submitted to
DEPARTMENT OF COMPUTER ENGINEERING,

GOVERNMENT POLYTECHNIC HINGOLI


2022-2023

1
GOVERNMENT POLYTECHNIC HINGOLI

Certificate

This is to certify that the project report entitled “GUI Calculator ” was
successfully completed by student of sixth semester diploma in Computer
Engineering.

NAME OF STUDENTS

PAWAR YASH SANJAY [2011630041]


SURAJ MOHAN KHANDARE [2011630068]
PRADIP GOVIND RATHOD [2011630043]
GOPAL MANOJ PADALKAR [2011630049]

In Partial Fulfillment Of The Requirements For The Award Of The Diploma In


Computer Engineering & Submitted To The Department Of Computer
Engineering Of Government Polytechnic Hingoli Work Carried Out During A
Period For The Academic Year 2022-2023 as Per Curriculum.

Mr. P. H. Gutte Prof. A.T.Adhave


Name of Guide Head of Department

Dr. Ashok Upadhyay


Principal

2
ACKNOWLEDGEMENT
"I would like to express my sincere gratitude to all those who have contributed

to the completion of this report. First and foremost, I would like to thank Prof.

Mr. P H Gutte, my supervisor, for providing guidance and support throughout this

report. Without their valuable insights, this report would not have been possible.

I would also like to extend my appreciation to Pradip Rathod,

Suraj Khandare, and Gopal Padalkar for their invaluable assistance in gathering

data and conducting research. Their contributions were essential in shaping the

outcome of this report. Additionally, I am thankful to DR. Ashok Upadhyay

(Principal of College) for providing me with the necessary resources and tools to

carry out this project.

Finally, I would like to acknowledge the support of my

family and friends, who have provided me with encouragement and motivation

throughout this journey.

Thank you all for your contributions, support, and encouragement. Your efforts

have been instrumental in making this report a success."

NAME OF STUDENT : YASH PAWAR

3
Index

SR. NO. CONTENT

1 Introduction

2 GUI Window Setup

3 Output Field Setup

4 Button Click Function

5 Math Operation Functions

6 Button Creation and Placement

7 Conclusion

4
1. Executive Summary

The GUI Calculator in Python is a user-friendly tool that allows users to


perform basic mathematical operations such as addition, subtra-
ction, multiplication, and division. With a clean and simple interface, users
can easily input values and receive quick results. Notable features of
the calculator include the ability to chain operations together and the option
to clear the display with a single button press. The calculator is ideal
for students, professionals, or anyone in need of a reliable and
easy-to-use mathematical tool.

2. Course Outcomes :

 Successful execution of the program without any errors or bugs.


 The graphical user interface (GUI) is displayed correctly, and the user can
interact with the calculator through buttons or input fields.
 The calculator performs basic mathematical operations such as addition,
subtraction, multiplication, and division accurately.
 The calculator may also include advanced operations such as
exponentiation, square root, and trigonometric functions.
 The calculator displays the results of calculations accurately and clearly.
 The program may include error handling to prevent the user from entering
invalid inputs or dividing by zero.
 The program may also include a clear button to reset the calculator or an
exit button to close the application.
 The program may have an aesthetically pleasing and user-friendly design.
 The code may be well-organized, documented, and follow best practices for
Python programming.
 The program may be scalable, allowing for future updates or
improvements.

5
3. Literature

"Python GUI Programming with Tkinter", "Python GUI Programming


Cookbook", and "Python 3 Tkinter Programming". A video course on
Udemy called "Python for Everybody" and a book called "Creating GUI
Applications with wxPython" are also good resources. These resources
cover the basics of creating GUI applications with Python, provide
examples of building a calculator application, and offer step-by-step
guidance on implementation.

4. Actual Methodology Followed :

Choose a GUI toolkit: Python has several popular GUI toolkits, such as
Tkinter, PyQt, and wxPython. Choose the one that best fits your needs and
familiarity with the toolkit.

Design the user interface: Decide on the layout of the calculator, including
the buttons, labels, and entry fields. Consider the user experience and
usability of the interface.

Create the GUI elements: Use the chosen GUI toolkit to create the
necessary elements of the user interface, such as buttons, labels, and entry
fields.

Define the calculator functions: Define the functions that perform the
calculations. For example, you could define a function to add two numbers
together or to calculate the square root of a number.

Implement the calculator logic: Use the functions you defined to implement
the calculator logic. For example, when the user clicks the "+" button, the
program should call the add function with the appropriate inputs.

Integrate the GUI and logic: Connect the GUI elements to the calculator
logic. For example, when the user clicks a button, the program should call
the appropriate function and update the display with the result.
6
Test and refine: Test the calculator thoroughly, and refine the user interface
and logic as necessary to improve its usability and functionality.

5. Actual Resources Used

Sr. No Name of Resource Specification Quantity

6. Outputs of The Micro- project :

 The result of a calculation: When the user performs a calculation, such as addition
or multiplication, the calculator should display the result on the screen.

 Error messages: If the user inputs invalid data, such as non-numeric characters, the
calculator should display an error message indicating that the input is invalid.

 Memory functions: Some calculators may have memory functions, such as storing a
value in memory or recalling a value from memory.

 Scientific functions: Scientific calculators may have additional functions, such as


trigonometric functions, logarithms, or exponential functions.

 Currency conversion: A calculator could be built with currency conversion features


that allows the user to convert between currencies.
7
 Unit conversion: Another possible feature is unit conversion, where the calculator
can convert between different units of measurement, such as converting between
miles and kilometers or between Fahrenheit and Celsius.

7. Skill Development /Learning out of these Micro- projects:

 Programming skills: Building a GUI calculator in Python involves


writing code to implement the user interface and calculator logic. This
will require you to develop programming skills such as writing
functions, handling user input, and implementing mathematical
operations.

 GUI development skills: Creating a GUI involves designing the user


interface and implementing the interface elements such as buttons,
labels, and entry fields. You will need to develop skills in designing
effective user interfaces, managing events, and integrating the GUI
with the underlying logic.

 Problem-solving skills: Building a GUI calculator requires you to


identify and solve problems that arise during the development
process. You will need to develop problem-solving skills such as
debugging code, identifying and resolving user interface issues, and
testing and refining the calculator's functionality.

 Learning new tools and libraries: To build a GUI calculator in Python,


you may need to learn new tools and libraries, such as the chosen GUI
toolkit or external libraries for performing specific calculations.
Learning new tools and libraries is an essential skill for a programmer,
as it allows you to expand your knowledge and capabilities.

8. Application of the Micro-Project:

 Education: A GUI calculator can be used in the classroom to teach


students basic mathematical operations or to demonstrate more
advanced concepts such as trigonometry or logarithms.

8
 Business: A GUI calculator can be used in business settings to perform
financial calculations such as interest rates, currency conversions, or
profit margins.

 Personal use: A GUI calculator can be used by individuals for personal


use, such as calculating mortgage payments or managing a budget.

 Engineering: A GUI calculator can be used in engineering or scientific


settings for performing complex calculations or converting units.

 Healthcare: A GUI calculator can be used in healthcare settings, such as


calculating dosages for medications or calculating body mass index
(BMI).

 Gaming: A GUI calculator can be used in gaming applications where


players need to calculate odds or probabilities.

9. Area of Future Improvement

 User interface design: The user interface design can always be improved
to make the calculator more user-friendly and visually appealing.
Consider incorporating modern design principles and making the
calculator responsive to different screen sizes.

 Functionality: Additional features can be added to the calculator, such


as more advanced mathematical functions, a history log of calculations,
or the ability to save and load calculations.

 Performance: Depending on the complexity of the calculator's


operations, performance may become an issue when dealing with
large numbers or complex calculations. Optimizing the code for
efficiency can improve the calculator's performance.

 Error handling: Error handling is crucial for ensuring that the


calculator works correctly and doesn't crash when the user inputs
invalid data. Improving the error handling mechanisms can make
the calculator more reliable and user-friendly.
9
 Testing: Extensive testing of the calculator can reveal any bugs or issues that may be
present. Improving the testing process can help ensure that the calculator works
correctly in all situations and with all inputs.

 Integration with other tools: The calculator can be integrated with other tools and
software, such as spreadsheet programs or databases, to provide a more
comprehensive set of features and capabilities.

 Introduction

A graphical user interface (GUI) calculator is a software application that enables


users to perform mathematical calculations using a visual interface. Python, a high-
level programming language, is a popular choice for building GUI calculators due to
its simplicity, flexibility, and rich set of libraries and frameworks. A GUI calculator
built in Python can offer a range of features such as basic arithmetic operations,
scientific functions, unit conversions, and memory functions, among others.
Additionally, a well-designed GUI can make the calculator easy to use and visually
appealing. Building a GUI calculator in Python can be an excellent micro-project for
beginners to learn programming, GUI development, problem-solving, and other
skills. Moreover, a GUI calculator can find applications in various fields such as
education, business, engineering, healthcare, and gaming, among others. By
continuously improving the functionality, user interface design, error handling,
testing, performance, and integration with other tools, a GUI calculator built in
Python can become a reliable, efficient, and user-friendly tool for mathematical
calculations.

 GUI Window Setup :

Setting up the GUI window for a GUI calculator in Python involves


creating a graphical interface using a GUI toolkit or library such as
Tkinter, PyQt, or wxPython. Here is an example of how to set up the
GUI window using Tkinter:

10
from tkinter import *

# Create a GUI window


window = Tk()
window.title("GUI Calculator")
window.geometry("400x400")

window.resizable(False, False)

# Add a label for displaying input and output


display_label = Label(window, text="", font=("Arial", 18), width=18,
height=2, anchor="e", bg="white", bd=0)
display_label.pack(pady=10)

# Add buttons for numbers and operations


button_1 = Button(window, text="1", font=("Arial", 16), width=4,
height=2, bd=0)
button_1.pack(side="left", padx=5, pady=5)

button_2 = Button(window, text="2", font=("Arial", 16), width=4,


height=2, bd=0)
button_2.pack(side="left", padx=5, pady=5)

# Add other buttons and functions as necessary

# Start the GUI main loop


window.mainloop()

 Output Field Setup :

The output field is an essential part of any GUI calculator. It displays


the input values and the result of calculations performed by the
calculator. The output field is typically implemented using a label
widget that is added to the calculator window. The label widget is then
updated with the input and output values as the user enters them.
11
In the code example provided, we first create an instance of the Label
class using the Label() function provided by the Tkinter library. We then
specify the properties of the label widget, such as the font, size, and
background color using the arguments of the Label() function.

Next, we add the label widget to the GUI window using the pack()
method, which arranges the widget in the window based on the size
and location of other widgets.

We also define a function called update_display() that takes a value as


input and updates the text of the label widget accordingly. This
function is called whenever the user clicks a number button on the
calculator. The update_display() function gets the current value of the
label widget using the "text" key of the dictionary returned by the label
widget object. It then concatenates the current value with the input
value and sets the "text" key of the label widget object to the
concatenated value.

Finally, we bind the number buttons to the update_display() function


using the bind() method. This method takes two arguments: the event
to bind to (in this case, the left mouse button click event <Button-1>),
and a function to call when the event occurs. We use a lambda
function to pass the button value as an argument to the
update_display() function.

 Button Click Function :

The button click function is a critical part of a GUI calculator. It is responsible for
performing the appropriate calculation when a user clicks on a button. In a
simple calculator, the button click function would be responsible for adding,
subtracting, multiplying, or dividing two numbers based on the user input.

12
In the code example provided, we define a function called button_click() that
takes an event object as an input parameter. This function is bound to each
number and operator button using the bind() method. When a user clicks a
button, the function is called with the associated event object as an input
parameter.

The button_click() function first gets the text value of the button that was clicked
using the event.widget["text"] syntax. It then updates the display field with the
button's text value using the update_display() function.

Next, the function checks if the button clicked was an operator (+, -, *, /) or the
equal button. If the button was an operator, the function sets the operator
variable to the value of the clicked button. If the button clicked was the equal
button, the function performs the appropriate calculation based on the current
operator and the input values stored in the first_number and second_number
variables.

Finally, the button_click() function updates the operator_clicked variable to True


if the button clicked was an operator or the equal button, indicating that the
calculator is ready for the second number input. If the button clicked was not an
operator, the function updates the operator_clicked variable to False, indicating
that the calculator is still waiting for the operator input.

 Math Operation Functions:

Math operation functions are essential for any GUI calculator. They are
responsible for performing arithmetic operations on the input values and
returning the result. In a simple calculator, the math operation functions would
be responsible for adding, subtracting, multiplying, or dividing two numbers.

In the code example provided, we define four math operation functions: add(),
subtract(), multiply(), and divide(). Each function takes two input parameters (x
and y) and returns the result of the appropriate arithmetic operation based on
the function name.

The add() function returns the sum of x and y, the subtract() function returns the
difference between x and y, the multiply() function returns the product of x and
y, and the divide() function returns the quotient of x and y.

In the button_click() function, we call the appropriate math operation function


based on the operator input by the user. For example, if the user clicks the "+"
13
operator button, we call the add() function with the input values stored in the
first_number and second_number variables. The result of the math operation is
then stored in the result variable and displayed in the output field using the
update_display() function.

 Button Creation and Placement:

The buttons are the primary way for users to input values and operators into the
calculator.

In the code example provided, we use the tkinter.Button() class to create each
button. We define a list of button labels (button_labels) and iterate over them to
create a button for each label. We also specify the button's size, font, and color
using the font and bg arguments.

To place the buttons on the calculator window, we use the grid() method to
specify the row and column positions of each button. We set the padx and pady
arguments to create padding between the buttons and the window edges.

We also bind the button_click() function to each button using the bind() method.
This ensures that the appropriate function is called when the user clicks a button.

 Conclusion :

Additionally, building a GUI calculator in Python can provide a foundation for


more complex GUI projects. Once you understand the basics of GUI design and
event handling, you can apply these concepts to build more advanced
applications such as data visualization tools, games, and productivity
applications.

Moreover, creating a GUI calculator in Python can be a great way to practice


collaboration skills. Working with a partner or a team can help to divide the
workload and bring diverse perspectives to the project. It can also provide
opportunities for peer learning and feedback, enhancing the learning experience.

Lastly, building a GUI calculator in Python can help to develop problem-solving


skills. As you encounter obstacles and bugs in the project, you will need to use
14
critical thinking and creativity to overcome them. These skills are valuable in
many areas of life and can be transferred to other programming and non-
programming tasks.

Teacher Evaluation Sheet for Micro Project

Course Title and Code: - Python Programming

Title of the Project: - : GUI Calculator.

Group No: -

COs addressed by the Micro Project:

CO :

CO :

CO :

CO :

Marks:-

Marks obtained by
the
Marks for Total
Name and designation of Faculty Member: individual
Roll No. Group Work Marks
Name Of Student based on viva
(06) (10)
(04)
3131 Yash Sanjay Pawar

3133 Pradip Govind Rathod


Signature:
3143 Suraj Mohan Khandare

3137 Gopal Manoj Padalkar

15

You might also like