-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalci.py
51 lines (39 loc) · 1.67 KB
/
calci.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
# CALCULATOR
import tkinter as tk
mainWindow = tk.Tk() # defining a window
mainWindow.title('CALCULATOR') # setting the title of the window
label1= tk.Label(mainWindow,text = 'ENTER FIRST NUMBER',pady=10 ,padx=10)
label1.pack()
text1= tk.Entry(mainWindow)
text1.pack()
label2= tk.Label(mainWindow,text = 'ENTER SECOND NUMBER',pady=10,padx=10)
label2.pack()
text2= tk.Entry(mainWindow)
text2.pack()
def sumIt(): # defining summation
first= int(text1.get())
second= int(text2.get())
result.config(text='result : '+str(first+second))
def subIt(): # defining subtraction
first = int(text1.get())
second= int(text2.get())
result.config(text='result : '+str(first-second))
def mulIt(): # defining multiplication
first = int(text1.get())
second = int(text2.get())
result.config(text=first*second)
def divIt(): # defining division
first = int(text1.get())
second = int(text2.get())
result.config(text = 'result :'+ str(first/second))
button1 = tk.Button(mainWindow,text='+',command=lambda:sumIt())
button2 = tk.Button(mainWindow,text='-',command=lambda:subIt())
button3 = tk.Button(mainWindow,text='*',command=lambda:mulIt())
button4 = tk.Button(mainWindow,text='/',command=lambda:divIt())
button1.pack()
button2.pack()
button3.pack()
button4.pack()
result =tk.Label(mainWindow)
result.pack()
mainWindow.mainloop()