1
+ from tkinter import *
2
+
3
+ root = Tk ()
4
+ root .title ("Calculator" )
5
+ root .configure (background = "black" )
6
+ root .iconbitmap ('icon.ico' )
7
+ #root.geometry("340x555")
8
+ root .minsize (340 , 555 )
9
+ root .maxsize (340 , 555 )
10
+
11
+
12
+ def click (event ):
13
+ global scvalue
14
+ text = event .widget .cget ("text" )
15
+ # print(text)
16
+ if text == "=" :
17
+ if scvalue .get ().isdigit ():
18
+ value = int (scvalue .get ())
19
+ else :
20
+ value = eval (screen .get ())
21
+ scvalue .set (value )
22
+ screen .update ()
23
+
24
+ elif text == "Clear" :
25
+ scvalue .set ("" )
26
+ screen .update ()
27
+
28
+ else :
29
+ scvalue .set (scvalue .get () + text )
30
+ screen .update ()
31
+
32
+ scvalue = StringVar ()
33
+ scvalue .set ("" )
34
+
35
+ screen = Entry (root , textvar = scvalue , font = "lucida 30 bold" )
36
+ screen .pack (fill = X , pady = 10 , padx = 10 )
37
+
38
+
39
+
40
+ f = Frame (root , bg = "black" )
41
+
42
+ b = Button (f , text = "Clear" , bg = "orange" , padx = 10 , pady = 10 , font = "lucida 25 bold" , width = 10 )
43
+ b .pack (side = LEFT , padx = 5 , pady = 5 )
44
+ b .bind ("<Button-1>" , click )
45
+
46
+ b = Button (f , text = "%" , bg = "orange" , padx = 10 , pady = 10 , font = "lucida 25 bold" , width = 2 )
47
+ b .pack (side = LEFT , padx = 5 , pady = 5 )
48
+ b .bind ("<Button-1>" , click )
49
+
50
+ f .pack ()
51
+
52
+
53
+
54
+ f = Frame (root , bg = "black" )
55
+
56
+ b = Button (f , text = "9" , bg = "orange" , padx = 10 , pady = 10 , font = "lucida 25 bold" , width = 2 )
57
+ b .pack (side = LEFT , padx = 5 , pady = 5 )
58
+ b .bind ("<Button-1>" , click )
59
+
60
+ b = Button (f , text = "8" , bg = "orange" , padx = 10 , pady = 10 , font = "lucida 25 bold" , width = 2 )
61
+ b .pack (side = LEFT , padx = 5 , pady = 5 )
62
+ b .bind ("<Button-1>" , click )
63
+
64
+ b = Button (f , text = "7" , bg = "orange" , padx = 10 , pady = 10 , font = "lucida 25 bold" , width = 2 )
65
+ b .pack (side = LEFT , padx = 5 , pady = 5 )
66
+ b .bind ("<Button-1>" , click )
67
+
68
+ b = Button (f , text = "/" , bg = "orange" , padx = 10 , pady = 10 , font = "lucida 25 bold" , width = 2 )
69
+ b .pack (side = LEFT , padx = 5 , pady = 5 )
70
+ b .bind ("<Button-1>" , click )
71
+
72
+ f .pack ()
73
+
74
+
75
+
76
+ f = Frame (root , bg = "black" )
77
+
78
+ b = Button (f , text = "6" , bg = "orange" , padx = 10 , pady = 10 , font = "lucida 25 bold" , width = 2 )
79
+ b .pack (side = LEFT , padx = 5 , pady = 5 )
80
+ b .bind ("<Button-1>" , click )
81
+
82
+ b = Button (f , text = "5" , bg = "orange" , padx = 10 , pady = 10 , font = "lucida 25 bold" , width = 2 )
83
+ b .pack (side = LEFT , padx = 5 , pady = 5 )
84
+ b .bind ("<Button-1>" , click )
85
+
86
+ b = Button (f , text = "4" , bg = "orange" , padx = 10 , pady = 10 , font = "lucida 25 bold" , width = 2 )
87
+ b .pack (side = LEFT , padx = 5 , pady = 5 )
88
+ b .bind ("<Button-1>" , click )
89
+
90
+ b = Button (f , text = "*" , bg = "orange" , padx = 10 , pady = 10 , font = "lucida 25 bold" , width = 2 )
91
+ b .pack (side = LEFT , padx = 5 , pady = 5 )
92
+ b .bind ("<Button-1>" , click )
93
+
94
+ f .pack ()
95
+
96
+
97
+
98
+ f = Frame (root , bg = "black" )
99
+
100
+ b = Button (f , text = "3" , bg = "orange" , padx = 10 , pady = 10 , font = "lucida 25 bold" , width = 2 )
101
+ b .pack (side = LEFT , padx = 5 , pady = 5 )
102
+ b .bind ("<Button-1>" , click )
103
+
104
+ b = Button (f , text = "2" , bg = "orange" , padx = 10 , pady = 10 , font = "lucida 25 bold" , width = 2 )
105
+ b .pack (side = LEFT , padx = 5 , pady = 5 )
106
+ b .bind ("<Button-1>" , click )
107
+
108
+ b = Button (f , text = "1" , bg = "orange" , padx = 10 , pady = 10 , font = "lucida 25 bold" , width = 2 )
109
+ b .pack (side = LEFT , padx = 5 , pady = 5 )
110
+ b .bind ("<Button-1>" , click )
111
+
112
+ b = Button (f , text = "+" , bg = "orange" , padx = 10 , pady = 10 , font = "lucida 25 bold" , width = 2 )
113
+ b .pack (side = LEFT , padx = 5 , pady = 5 )
114
+ b .bind ("<Button-1>" , click )
115
+
116
+ f .pack ()
117
+
118
+
119
+
120
+ f = Frame (root , bg = "black" )
121
+
122
+ b = Button (f , text = "." , bg = "orange" , padx = 10 , pady = 10 , font = "lucida 25 bold" , width = 2 )
123
+ b .pack (side = LEFT , padx = 5 , pady = 5 )
124
+ b .bind ("<Button-1>" , click )
125
+
126
+ b = Button (f , text = "0" , bg = "orange" , padx = 10 , pady = 10 , font = "lucida 25 bold" , width = 2 )
127
+ b .pack (side = LEFT , padx = 5 , pady = 5 )
128
+ b .bind ("<Button-1>" , click )
129
+
130
+ b = Button (f , text = "=" , bg = "orange" , padx = 10 , pady = 10 , font = "lucida 25 bold" , width = 2 )
131
+ b .pack (side = LEFT , padx = 5 , pady = 5 )
132
+ b .bind ("<Button-1>" , click )
133
+
134
+ b = Button (f , text = "-" , bg = "orange" , padx = 10 , pady = 10 , font = "lucida 25 bold" , width = 2 )
135
+ b .pack (side = LEFT , padx = 5 , pady = 5 )
136
+ b .bind ("<Button-1>" , click )
137
+
138
+ f .pack ()
139
+
140
+
141
+ root .mainloop ()
0 commit comments