Evaluate the Mathematical Expressions using Tkinter in Python
Last Updated :
17 Feb, 2022
This article focuses on the evaluation of mathematical expression using the Tkinter and math packages 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 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.
PYTHON
import tkinter as tk
from math import *
from tkinter import messagebox
def eval_expression(event):
result.configure(text = " Result: " +
str ( eval (entry.get())))
messagebox.showinfo( "Evaluate Expression" ,
"Successfully evaluated" )
root = tk.Tk()
root.geometry( '300x150+600+200' )
root.title( 'Evaluate Expression' )
input_label = tk.Label(root,
text = " Enter Your Expression:" ,).grid(row = 1 )
entry = tk.Entry(root)
entry.bind("
|
OUTPUT :
Evaluate expression GUI
Evaluate expression working
Below is a video that demonstrates the execution of the code in PyCharm:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...