Introduction
Introduction
zeeA Graphical User Interface (GUI) calculator is a software application that provides a visual
representation of a calculator on a computer screen. Unlike traditional calculators, GUI calculators
offer a more intuitive and user-friendly experience by utilizing buttons, input fields, and other
graphical elements. These calculators allow users to perform various mathematical operations with
ease and often come equipped with additional features that cater to specific needs.
Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI
methods, Tkinter is the 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 GUI
applications. Creating a GUI using Tkinter is an easy task.
To create a Tkinter:
Let’s create a GUI-based simple calculator using the Python Tkinter module, which can perform basic
arithmetic operations addition, subtraction, multiplication, and division.
expression = ""
def press(num):
global expression
# concatenation of string
equation.set(expression)
def equalpress():
try:
global expression
# into string
total = str(eval(expression))
equation.set(total)
# by empty string
expression = ""
except:
expression = ""
def clear():
global expression
expression = ""
equation.set("")
# Driver code
if _name_ == "_main_":
gui = Tk()
gui.configure(background="light green")
gui.title("Simple Calculator")
gui.geometry("270x150")
equation = StringVar()
button1.grid(row=2, column=0)
button2.grid(row=2, column=1)
button3.grid(row=2, column=2)
button4.grid(row=3, column=0)
button5.grid(row=3, column=1)
button6.grid(row=3, column=2)
button7.grid(row=4, column=0)
button8.grid(row=4, column=1)
button0.grid(row=5, column=0)
plus.grid(row=2, column=3)
minus.grid(row=3, column=3)
multiply.grid(row=4, column=3)
divide.grid(row=5, column=3)
equal.grid(row=5, column=2)
clear.grid(row=5, column='1')
Decimal.grid(row=6, column=0)
gui.mainloop()
OUTPUT:
Code Explanation:
CONCLUSION:
A GUI calculator with aim is a valuable tool that combines the convenience of a graphical user
interface with the ability to perform specialized calculations or tasks. It provides users with a user-
friendly interface that simplifies complex calculations, automates repetitive tasks, or streamlines
processes related to a specific field or industry.