Repository navigation
Expand file tree
/
Copy pathsolve.py
More file actions
52 lines (40 loc) 路 1.42 KB
/
Copy pathsolve.py
File metadata and controls
52 lines (40 loc) 路 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import calculator
import tkinter as tk
window = tk.Tk()
window.title("calculator".upper())
label1 = tk.Label(text="WELCOME TO MY BASIC CALCULATOR!!!".upper())
label1.pack()
tk.Label(window, text="ENTER FIRST NUMBER:").pack()
num1_entry = tk.Entry(window)
num1_entry.pack()
tk.Label(window, text="ENTER ANY OPERATOR:").pack()
operator_entry = tk.Entry(window)
operator_entry.pack()
tk.Label(window, text="ENTER SECOND NUMBER:").pack()
num2_entry = tk.Entry(window)
num2_entry.pack()
# Result label
result_label = tk.Label(window, text="RESULTS = 馃憠 ")
result_label.pack()
def calculate():
try:
num1 = float(num1_entry.get())
num2 = float(num2_entry.get())
operator = operator_entry.get()
if operator == "+":
result = calculator.add(num1, num2)
elif operator == "-":
result = calculator.subtract(num1, num2)
elif operator == "*":
result = calculator.multiply(num1, num2)
elif operator == "/":
result = calculator.divide(num1, num2)
elif operator == "%":
result = calculator.modulo(num1, num2)
else:
result = "Invalid operator 鈽狅笍馃拃馃懝"
except ValueError:
result = "Error: Invalid input"
result_label.config(text=f"RESULTS = 馃憠 {result}")
tk.Button(window, text="ANSWER", command=calculate).pack()
window.mainloop()