Evaluate the Mathematical Expressions using Tkinter in Python

This article focuses on evaluation of mathematical expression using the Tkinter  and math packeges in Python. 

Tkinter: Python Tkinter is a GUI programming package or built-in package. Tkinter provides the Tk GUI toolkit with a potent object-oriented interface. Python with tkinter is the fastest and easiest way to create the GUI applications. Creating a GUI using tkinter is an easy task. 

Math module: In python, a variety of mathematical operations can be carried out with ease by importing a python  module called “math” that specifies various functions, making our tasks simpler. 

Steps involved in conversion of temperature:

  • Importing the  tkinter & math packages.
  • Create the main window.
  • Add number of widgets to the main window : Entry , Label.
  • Evaluating the expression.
  • Displaying message.
  • Apply the event trigger on the widgets.







# Importing tkinter module as tk
import tkinter as tk
# Importing all functions/methods
# from math module
from math import *
# Import messagebox class from tkinter
from tkinter import messagebox
# function for evaluating the expression
def eval_expression(event):
    result.configure(text = " Result: " + 
    messagebox.showinfo("Evaluate Expression"
                        "Successfully evaluated" )
# creating Tk window
root = tk.Tk()
# set geometry of root window
# set the title of root window
root.title('Evaluate Expression')
# label and entry field
input_label = tk.Label(root, 
                      text = " Enter Your Expression:",).grid(row = 1)
entry = tk.Entry(root)
# bind 'enter' event to the 
# eval_expression() through
# entry widget



Evaluate expression gui

Evaluate expression gui

Evaluate expression working

Evaluate expression working


Below is a video which demonstrates the execution of the code in PyCharm:


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.