-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculatorApp.py
63 lines (39 loc) · 1.33 KB
/
CalculatorApp.py
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
53
54
55
56
57
58
59
60
61
62
63
from tkinter import *
import tkinter
import tkinter.messagebox
top = tkinter.Tk()
top.title("Calculator")
L1 = Label(top,text="My Calculator",).grid(row=0,column=1)
L2 = Label(top,text="Number 1",).grid(row=1,column=0)
L3 = Label(top,text="Number 2",).grid(row=2,column=0)
L4 = Label(top,text="Operator",).grid(row=3,column=0)
L5 = Label(top, text="Answer",).grid(row=4,column=0)
E1 = Entry(top, bd = 0.5)
E1.grid(row=1,column=1)
E2 = Entry(top, bd =0.5)
E2.grid(row=2,column=1)
E3 = Entry(top, bd = 0.5)
E3.grid(row=3,column=1)
E4 = Entry(top, bd =0.5)
E4.grid(row=4,column=1)
def process():
try:
number1 = Entry.get(E1)
number2 = Entry.get(E2)
operator = Entry.get(E3)
number1 = int(number1)
number2 = int(number2)
if operator == "+":
answer = number1+number2
if operator == "-":
answer = number1-number2
if operator == "*":
answer = number1*number2
if operator == "/":
answer = number1/number2
Entry.insert(E4,0,answer)
print(answer)
except ValueError:
tkinter.messagebox.showwarning("Warning", "Please enter the value in integer")
B = Button(top, text="Submit", command= process).grid(row=5, column=1,)
top.mainloop()