forked from seeditsolution/pythonprogram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimple_calculator.py
More file actions
123 lines (100 loc) · 3.42 KB
/
Copy pathSimple_calculator.py
File metadata and controls
123 lines (100 loc) · 3.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
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
122
123
from tkinter import *
def click(event):
global scvalue
text=event.widget.cget("text")
# print(text)
if text == "=":
if scvalue.get().isdigit():
value = int(scvalue.get())
else:
try:
value = eval(screen.get())
except Exception as e:
print(e)
value = "Error"
scvalue.set(value)
screen.update()
elif text=="C":
scvalue.set("")
screen.update()
pass
else:
scvalue.set(scvalue.get() + text)
screen.update()
root=Tk()
root.geometry("200x400")
root.title("Calculator")
root.maxsize(200,400)
root.config(bg="black")
root.wm_iconbitmap("download.ico")
scvalue=StringVar()
scvalue.set("")
screen=Entry(root,textvar=scvalue,font="lucida 20 bold",bg="white",fg="black")
screen.pack(fill=X,ipadx=6,pady=4,padx=6)
f1=Frame(root,bg="black",width=10)
f1.pack()
b=Button(f1,text="7",padx=6,pady=4,font="lucida 15 bold",bg="orange")
b.pack(side=LEFT,padx=6,pady=4)
b.bind("<Button-1>",click)
b=Button(f1,text="8",padx=6,pady=4,font="lucida 15 bold",bg="orange")
b.pack(side=LEFT,padx=6,pady=4)
b.bind("<Button-1>",click)
b=Button(f1,text="9",padx=6,pady=4,font="lucida 15 bold",bg="orange")
b.pack(side=LEFT,padx=6,pady=4)
b.bind("<Button-1>",click)
f1=Frame(root,bg="black")
f1.pack()
b=Button(f1,text="4",padx=6,pady=4,font="lucida 15 bold",bg="orange")
b.pack(side=LEFT,padx=6,pady=4)
b.bind("<Button-1>",click)
b=Button(f1,text="5",padx=6,pady=4,font="lucida 15 bold",bg="orange")
b.pack(side=LEFT,padx=6,pady=4)
b.bind("<Button-1>",click)
b=Button(f1,text="6",padx=6,pady=4,font="lucida 15 bold",bg="orange")
b.pack(side=LEFT,padx=6,pady=4)
b.bind("<Button-1>",click)
f1=Frame(root,bg="black")
f1.pack()
b=Button(f1,text="1",padx=6,pady=4,font="lucida 15 bold",bg="orange")
b.pack(side=LEFT,padx=6,pady=4)
b.bind("<Button-1>",click)
b=Button(f1,text="2",padx=6,pady=4,font="lucida 15 bold",bg="orange")
b.pack(side=LEFT,padx=6,pady=4)
b.bind("<Button-1>",click)
b=Button(f1,text="3",padx=6,pady=4,font="lucida 15 bold",bg="orange")
b.pack(side=LEFT,padx=6,pady=4)
b.bind("<Button-1>",click)
f1=Frame(root,bg="black")
f1.pack()
b=Button(f1,text="0",padx=6.1,pady=4,font="lucida 15 bold",bg="orange")
b.pack(side=LEFT,padx=6.2,pady=4)
b.bind("<Button-1>",click)
b=Button(f1,text="+",padx=5.6,pady=4,font="lucida 15 bold",bg="orange")
b.pack(side=LEFT,padx=5.5,pady=3)
b.bind("<Button-1>",click)
b=Button(f1,text="-",padx=6.5,pady=3,font="lucida 16 bold",bg="orange")
b.pack(side=LEFT,padx=6,pady=3)
b.bind("<Button-1>",click)
f1=Frame(root,bg="black")
f1.pack()
b=Button(f1,text="*",padx=6.5,pady=3,font="lucida 15 bold",bg="orange")
b.pack(side=LEFT,padx=6.3,pady=4)
b.bind("<Button-1>",click)
b=Button(f1,text="/",padx=7,pady=3,font="lucida 16 bold",bg="orange")
b.pack(side=LEFT,padx=7,pady=3)
b.bind("<Button-1>",click)
b=Button(f1,text="%",padx=2.5,pady=4,font="lucida 14 bold",bg="orange")
b.pack(side=LEFT,padx=6.1,pady=5)
b.bind("<Button-1>",click)
f1=Frame(root,bg="black")
f1.pack()
b=Button(f1,text="C",padx=6.3,pady=6,font="lucida 13 bold",bg="orange")
b.pack(side=LEFT,padx=6.1,pady=3)
b.bind("<Button-1>",click)
b=Button(f1,text=".",padx=6.8,pady=0.7,font="lucida 15 bold",bg="orange")
b.pack(side=LEFT,padx=6.8,pady=3)
b.bind("<Button-1>",click)
b=Button(f1,text="=",padx=6.1,pady=1,font="lucida 15 bold",bg="orange")
b.pack(side=LEFT,padx=6.3,pady=3)
b.bind("<Button-1>",click)
root.mainloop()