# Simple GUI Calculator Using Tkinter In Python We will make a Simple GUI Calculator Using Tkinter In Python which is a python module to make GUI applications simply so that’s why we will use it to make a GUI Calculator Using tkinter

Here we are going to provide you with the source code with a complete explanation so that you can easily make your GUI Calculator Using tkinter

## Source Code

```# importing the tkinter module
from tkinter import *

# initializing the tkinter
root = Tk()

# setting the width and height of the gui
root.geometry("430x500")    # x is small case here

# declaring an empty string variable
expression = ""

# defining function which will set expressions and answers to the  user
def setexpression(num):
global expression
expression = expression + str(num)
value.set(expression)

# defining a function to calculate the expression entered by the user
def calculator():
try:
global expression
except:
value.set("Enter correct expression")
expression = ""

# function to clear everything in expression
def clear():
global expression
expression = ""
value.set(expression)

# declaring font variables as ("Language", size)
large_font = ('Verdana', 15)
small_font = ('Verdana', 10)

# declaring variable to take value of expression entered by the user
value = StringVar(value="Enter expression")

# entry widget to take expression from user and to show
# calculations
Entry(root, textvariable=value, font=large_font).grid(row=0,

# Now, there are some most basic buttons which should be present
# in a calculator
# here, each button is calling the setexpression function which
# is used to set values in the entry widget entered by the user
# on pressing the buttons 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, .
Button(root, text="+", fg="red", command=lambda:
Button(root, text="-", fg="red", command=lambda:
setexpression("-"), height=4, width=8).grid(row=2, column=0, pady=10)
Button(root, text="X", fg="red", command=lambda:
setexpression("*"), height=4, width=8).grid(row=3, column=0,pady=10)
Button(root, text="/", fg="red", command=lambda:
setexpression("/"), height=4, width=8).grid(row=4, column=0,pady=10)
Button(root, text="1", fg="red", command=lambda:
setexpression("1"), height=4, width=8).grid(row=1, column=1,pady=10)
Button(root, text="2", fg="red", command=lambda:
setexpression("2"), height=4, width=8).grid(row=1, column=2,pady=10)
Button(root, text="3", fg="red", command=lambda:
setexpression("3"), height=4, width=8).grid(row=1, column=3,pady=10)
Button(root, text="4", fg="red", command=lambda:
setexpression("4"), height=4, width=8).grid(row=2, column=1,pady=10)
Button(root, text="5", fg="red", command=lambda:
setexpression("5"), height=4, width=8).grid(row=2, column=2)
Button(root, text="6", fg="red", command=lambda:
setexpression("6"), height=4, width=8).grid(row=2, column=3,pady=10)
Button(root, text="7", fg="red", command=lambda:
setexpression("7"), height=4, width=8).grid(row=3, column=1,pady=10)
Button(root, text="8", fg="red", command=lambda:
setexpression("8"), height=4, width=8).grid(row=3, column=2,pady=10)
Button(root, text="9", fg="red", command=lambda:
setexpression("9"), height=4, width=8).grid(row=3, column=3,pady=10)
Button(root, text="0", fg="red", command=lambda:
setexpression("0"), height=4, width=8).grid(row=4, column=2,pady=10)
Button(root, text=".", fg="red", command=lambda:
setexpression("."), height=4, width=8).grid(row=4, column=1,pady=10)

# "=" button to call the calculator button which will return and
# show the calculated value in the entry widget
Button(root, text="=", fg="red", command=calculator, height=4,

# "Clear" button to call the clear function which will clear the
# entry widget so that the user can start clculating again
Button(root, text="Clear", fg="red", command=clear, height=4,

# .mainloop() is used when the code is ready to run
root.mainloop()```

## Watch YouTube Video:

Keep updated for more amazing content like this

### Make money with Python in 2022

Did you know that data science was the fifth most common job on LinkedIn in 2017? Did you know that the demand for Python programmers is expected to grow by 19% from 2020-2021? Did you know that Python is one of the fastest-growing programming languages, and it will likely continue to expand as its adoption…

Continue Reading Make money with Python in 2022

### Top 15 Python Libraries For Data Science in 2022

Introduction In this informative article, we look at the most important Python Libraries For Data Science and explain how their distinct features may help you develop your data science knowledge. Python has a rich data science library environment. It’s almost impossible to cover everything in a single article. As a consequence, we’ve compiled a list…

Continue Reading Top 15 Python Libraries For Data Science in 2022

### Top 15 Python Libraries For Machine Learning in 2022

Introduction  In today’s digital environment, artificial intelligence (AI) and machine learning (ML) are getting more and more popular. Because of their growing popularity, machine learning technologies and algorithms should be mastered by IT workers. Specifically, Python machine learning libraries are what we are investigating today. We give individuals a head start on the new year…

Continue Reading Top 15 Python Libraries For Machine Learning in 2022

### File Explorer in Python using Tkinter

Introduction Welcome to copyassignment.com. In this tutorial, we are going to learn File Explorer in Python using the Tkinter module. What is basically a file explorer? A file explorer is nothing but an application that is used to manage certain files and folders on your device where we can open, edit, copy, delete and move…

Continue Reading File Explorer in Python using Tkinter

### Drawing Application in Python Tkinter

Introduction In this article, we will design and construct a basic Drawing Application in Python Tkinter GUI, where we can simply draw something on the canvas using a pencil and erase with an eraser, as well as the ability to change the thickness of a pencil and eraser. We may also modify the canvas’s background…

Continue Reading Drawing Application in Python Tkinter

### Sequel Programming Languages(SQL)

In this article, we are going to learn about Sequel Programming Languages(SQL). Big enterprises like Facebook, Instagram, and LinkedIn, use SQL for storing the data in the back-end. So, If you want to get a job in the field of data, then it is the most important query language to learn. Before getting started, let…

Continue Reading Sequel Programming Languages(SQL) #### Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at admin@copyassignment.com Thank you

## 3 thoughts on “Simple GUI Calculator Using Tkinter In Python”

1. TechnoHead says:

in your source code in line 52 is an “h” missing in front of eight…
should be “height”….
than it works fine, thanks 🙂

1. Harry says:

thanks for the help

2. sjhdfwjh says:

Brilliant post this match. I was checking constantly this vortal and Im ecciting! Extremely useful info specifically the last post 🙂 I was looking for this particular info for a long time. Thank you and good luck…