from tkinter import *
import math
while True:
ans = 0
root = Tk()
root.wm_attributes('-topmost', 1)
root.wm_title("Calculator")
num_entry1 = IntVar()
num_entry2 = IntVar()
entry1 = Entry(root, textvariable=num_entry1, width=53)
entry1.pack()
entry1.delete(0, END)
entry1.insert(0, "0")
entry2 = Entry(root, textvariable=num_entry2, width=53)
entry2.pack()
entry2.delete(0, END)
entry2.insert(0, "0")
answer = Text(root, width=40, height=2)
answer.pack()
answer.insert("1.0", ans)
answer.config(state=DISABLED)
operation = StringVar(root)
operation.set("Add")
option = OptionMenu(root, operation, "Add", "Subtract", "Multiply", "Divide (Float)", "X^Y",
"√num1", "√num2", "num1!", "num2!", "Pythagoras")
option.pack()
def calc():
global ans
num1 = num_entry1.get()
num2 = num_entry2.get()
op = operation.get()
if op == 'Add':
ans = num1 + num2
elif op == 'Subtract':
ans = num1 - num2
elif op == 'Multiply':
ans = num1 * num2
elif op == 'Divide (Float)':
ans = num1 / num2
elif op == 'X^Y':
ans = num1 ** num2
elif op == '√num1':
ans = math.sqrt(num1)
elif op == '√num2':
ans = math.sqrt(num2)
elif op == 'num1!':
ans = math.factorial(num1)
elif op == 'num2!':
ans = math.factorial(num2)
elif op == 'Pythagoras':
ans = math.sqrt(((num1 ** 2) + (num2 ** 2)))
else:
pass
answer.config(state=NORMAL)
answer.delete("1.0", END)
answer.insert("1.0", ans)
answer.config(state=DISABLED)
return
def calcquit():
global z
z = 1
root.destroy()
button1 = Button(root, text="Calculate", command=calc)
button1.pack()
button2 = Button(root, text="Quit", command=calcquit)
button2.pack()
mainloop()
if z == 1:
break
else:
pass