import tkinter as tk
def on_button_click(value):
current_text = [Link]()
[Link](0, [Link])
[Link]([Link], current_text + value)
def clear_entry():
[Link](0, [Link])
def calculate_result():
try:
expression = [Link]()
result = eval(expression)
[Link](0, [Link])
[Link]([Link], str(result))
except Exception as e:
[Link](0, [Link])
[Link]([Link], "Error")
# Create the main window root = [Link]() [Link]("Simple Calculator")
# Entry widget for displaying input and results entry = [Link](root, width=20, font=('Arial', 14))
[Link](row=0, column=0, columnspan=4)
# Buttons for digits and operations buttons = [
('7', 1, 0), ('8', 1, 1), ('9', 1, 2), ('/', 1, 3),
('4', 2, 0), ('5', 2, 1), ('6', 2, 2), ('*', 2, 3),
('1', 3, 0), ('2', 3, 1), ('3', 3, 2), ('-', 3, 3),
('0', 4, 0), ('C', 4, 1), ('=', 4, 2), ('+', 4, 3)
]
for (text, row, col) in buttons:
button = [Link](root, text=text, width=5, height=2, command=lambda t=text:
on_button_click(t))
[Link](row=row, column=col)
# Event for the clear button [Link]('<Escape>', lambda event: clear_entry())
# Event for the equals button [Link]('<Return>', lambda event: calculate_result())
# Set the window size [Link]("300x300")
# Run the main loop [Link]()
OUTPUT: