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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121 | from tkinter import *
from tkinter.messagebox import *
root=Tk()
root.title("CALCULATOR-BY SARTHAK PATEL")
root.resizable(False,False)
root.iconbitmap(r"C:\Users\sonam\Desktop\sarthak\cc.ico")
def clear():
input_1.delete(0,END)
def function(num):
b=num
text=b
if text=="=":
try:
d=input_1.get()
result=eval(d)
input_1.delete(0,END)
input_1.insert(0,result)
return
except Exception as er:
showerror("Invalid Format",er)
input_1.insert(END,text)
def function2(sc):
import math
b=sc
text=b
if text=="^":
d=input_1.get()
res=eval(d + "**2")
input_1.delete(0,END)
input_1.insert(0,res)
return
elif text=="^3":
e=input_1.get()
resu=eval(e + "**3")
input_1.delete(0,END)
input_1.insert(0,resu)
return
elif text=="^^":
e=input_1.get()
l=int(e)
resu=math.sqrt(l)
input_1.delete(0,END)
input_1.insert(0,resu)
return
input_1=Entry(root,font=("Arial",15),justify="right",borderwidth=4)
input_1.grid(ipady=20,ipadx=250,columnspan=5)
Button_1=Button(root,text="1",command=lambda:function("1"),padx=60,pady=30,font=("Arial",15))
Button_1.grid(row=3,column=1)
Button_2=Button(root,text="2",command=lambda:function("2"),padx=60,pady=30,font=("Arial",15))
Button_2.grid(row=3,column=2)
Button_3=Button(root,text="3",command=lambda:function("3"),padx=60,pady=30,font=("Arial",15))
Button_3.grid(row=3,column=3)
Button_4=Button(root,text="4",command=lambda:function("4"),padx=60,pady=30,font=("Arial",15))
Button_4.grid(row=2,column=1)
Button_5=Button(root,text="5",command=lambda:function("5"),padx=60,pady=30,font=("Arial",15))
Button_5.grid(row=2,column=2)
Button_6=Button(root,text="6",command=lambda:function("6"),padx=60,pady=30,font=("Arial",15))
Button_6.grid(row=2,column=3)
Button_7=Button(root,text="7",command=lambda:function("7"),padx=60,pady=30,font=("Arial",15))
Button_7.grid(row=1,column=1)
Button_8=Button(root,text="8",command=lambda:function("8"),padx=60,pady=30,font=("Arial",15))
Button_8.grid(row=1,column=2)
Button_9=Button(root,text="9",command=lambda:function("9"),padx=60,pady=30,font=("Arial",15))
Button_9.grid(row=1,column=3)
Button_0=Button(root,text="0",command=lambda:function("0"),padx=60,pady=30,font=("Arial",15))
Button_0.grid(row=4,column=2)
Button_div=Button(root,text="÷",command=lambda:function("/"),padx=60,pady=30,font=("Arial",15),bg="lightgrey")
Button_div.grid(row=1,column=4)
Button_add=Button(root,text="+",command=lambda:function("+"),padx=60,pady=30,font=("Arial",15),bg="lightgrey")
Button_add.grid(row=2,column=4)
Button_min=Button(root,text="-",command=lambda:function("-"),padx=63,pady=30,font=("Arial",15),bg="lightgrey")
Button_min.grid(row=3,column=4)
Button_mul=Button(root,text="×",command=lambda:function("*"),padx=60,pady=30,font=("Arial",15),bg="lightgrey")
Button_mul.grid(row=4,column=4)
Button_clear=Button(root,text="C",padx=60,pady=30,font=("Arial",15),bg="lightgrey",command=clear)
Button_clear.grid(row=4,column=1)
Button_equal=Button(root,text="=",command=lambda:function("="),padx=60,pady=30,font=("Arial",15),bg="lightgrey")
Button_equal.grid(row=4,column=3)
Button_root=Button(root,text="√",command=lambda:function2("^^"),padx=63,pady=30,font=("Arial",15),bg="lightgrey")
Button_root.grid(row=1,column=0)
Button_square=Button(root,text="x\u00b2",command=lambda:function2("^"),padx=60,pady=30,font=("Arial",15),bg="lightgrey")
Button_square.grid(row=2,column=0)
Button_cube=Button(root,text="x\u00b3",command=lambda:function2("^3"),padx=60,pady=30,font=("Arial",15),bg="lightgrey")
Button_cube.grid(row=3,column=0)
Button_root=Button(root,text=".",command=lambda:function("."),padx=64,pady=30,font=("Arial",15),bg="lightgrey")
Button_root.grid(row=4,column=0)
root.mainloop()
|
0 Comments