-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI_Calculator.py
More file actions
60 lines (56 loc) · 1.42 KB
/
GUI_Calculator.py
File metadata and controls
60 lines (56 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
53
54
55
56
57
58
59
import tkinter as tk
from cProfile import label
from calendar import error
def sum(a,b):
print(a+b)
result_label = tk.Label(root, text=(a,"+",b,"=",a+b))
result_label.pack()
def sub(a,b):
print(a-b)
result_label2=tk.Label(root,text=(a,"-",b,"=",a-b))
result_label2.pack()
def mult(a,b):
print(a*b)
reuslt_label4=tk.Label(root,text=(a,"x",b,"=",a*b))
reuslt_label4.pack()
def div(a,b):
print(a/b)
result_label3=tk.Label(root,text=(a,"/",b,"=",a/b))
result_label3.pack()
def error():
display_label=tk.Label(root,text="Enter correct Expression")
display_label.pack()
def calci():
#num1=length_entry.get() for text only
num1=int(length_entry1.get())
num2=int(length_entry2.get())
num3= length_entry3.get()
if(num3=='+'):
sum(num1,num2)
elif(num3=='-'):
sub(num1,num2)
elif(num3=='*'):
mult(num1,num2)
elif(num3=='/') :
div(num1,num2)
else:
error()
#creating window
root=tk.Tk()
root.title("Calculator")
root.geometry("400x400")
#to print text
length_label=tk.Label(root,text="Welcome to Gui Calculator")
length_label.pack()
#for fisrt number
length_entry1=tk.Entry(root)
length_entry1.pack(pady=10)
#for second number
length_entry2=tk.Entry(root)
length_entry2.pack(pady=10)
#result
length_entry3=tk.Entry(root)
length_entry3.pack(pady=10)
button=tk.Button(root,text="Calculate",command=calci)
button.pack()
root.mainloop()