Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Aadi_2310991753.py #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions Aadi_2310991753.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import tkinter as tk
import math

def on_click(event):
text = event.widget.cget("text")

if text == "=":
try:
result = eval(entry.get())
entry.delete(0, tk.END)
entry.insert(tk.END, str(result))
except:
entry.delete(0, tk.END)
entry.insert(tk.END, "Error")
elif text == "C":
entry.delete(0, tk.END)
elif text in ["sin", "cos", "tan", "log"]:
try:
if text == "sin":
sin_result = math.sin(math.radians(float(entry.get())))
entry.delete(0, tk.END)
entry.insert(tk.END, str(sin_result))
elif text == "cos":
cos_result = math.cos(math.radians(float(entry.get())))
entry.delete(0, tk.END)
entry.insert(tk.END, str(cos_result))
elif text == "tan":
tan_result = math.tan(math.radians(float(entry.get())))
entry.delete(0, tk.END)
entry.insert(tk.END, str(tan_result))
elif text == "log":
log_result = math.log10(float(entry.get()))
entry.delete(0, tk.END)
entry.insert(tk.END, str(log_result))
except:
entry.delete(0, tk.END)
entry.insert(tk.END, "Error")
else:
entry.insert(tk.END, text)

root = tk.Tk()
root.title("Graphical Calculator")

entry = tk.Entry(root, width=40, borderwidth=5)
entry.grid(row=0, column=0, columnspan=4)

buttons = [
"7", "8", "9", "/",
"4", "5", "6", "*",
"1", "2", "3", "-",
"C", "0", "=", "+",
"√", "sin", "cos", "tan", "log"
]

row = 1
col = 0

for button in buttons:
btn = tk.Button(root, text=button, padx=20, pady=10)
btn.grid(row=row, column=col)
btn.bind("<Button-1>", on_click)

col += 1
if col > 3:
col = 0
row += 1

root.mainloop()