-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
263 lines (237 loc) · 8.43 KB
/
main.py
File metadata and controls
263 lines (237 loc) · 8.43 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# Khai bao thu vien tkinter
from tkinter import *
# Set chuc nang cho cac nut bam
def Button_click(number):
global Operator
Operator += str(number)
Text_Input.set(Operator)
# Set chuc nang cho nut clear (xoa toan bo)
def Button_clear():
global Operator
Operator = ""
Text_Input.set("")
# Set chuc nang cho nut bang
def Button_equals():
global Operator
# Ham eval(): tinh toan bieu thuc so hoc
result = str(eval(Operator))
Text_Input.set(result)
# Set chuc nang cho nut ~ (xoa phan tu vua nhap truoc do)
def Button_clear1():
global Operator
#De lay du lieu duoc nhap vao tu man hinh hay bat cu loai text nao ta dung <Ten bien>.get()
Operator = Text_Input.get()
Operator = Operator[0:len(Operator)-1]
#De hien thi gia tri cua bien ra ma hinh ta dung: <Ten bien>.set(<Gia tri muon hien thi>)
Text_Input.set(Operator)
# Set cau hinh cho cua so hien len
Screen = Tk()
Screen.title(string='Calculator')
Screen.iconbitmap(r'c:\Users\Nguye\OneDrive\Máy tính\work_space\project_with_python\may_tinh_cam_tay\logo.ico')
#Screen.geometry("320x500+1000+100")
Screen['background']='#222222'
Screen.resizable(False, False)
Operator = ""
Text_Input = StringVar()
# Set cau hinh cho man hinh hien thi
Display = Entry(Screen,
# width = 16 co nghia la do rong bang 16 ky tu lien tiep
width = 16,
font = ('arial', 30, 'bold'),
textvariable=Text_Input,
bd = 10,
insertwidth=4,
bg = '#222222',
justify = 'right',
fg = "white").grid(columnspan = 4)
space = Label(Screen, pady = 5, bg = '#222222').grid(row=1,column=0)
# Set cau hinh cho nut 7, padx: chieu dai, fg: mau chu.
Button_7 = Button(Screen,
padx = 24,
#bd = 8,
fg = 'white',
font = ('arial', 25, 'bold'),
text = "7",
command=lambda:Button_click(7),
bg = '#444444').grid(row = 2, column = 0)
# Set cau hinh cho nut 8
Button_8 = Button(Screen,
padx = 24,
#bd = 8,
fg = 'white',
font = ('arial', 25, 'bold'),
text = "8",
command=lambda:Button_click(8),
bg = '#444444').grid(row = 2, column = 1)
# Set cau hinh cho nut 9
Button_9 = Button(Screen,
padx = 24,
#bd = 8,
fg = 'white',
font = ('arial', 25, 'bold'),
command=lambda:Button_click(9),
text = "9",
bg = '#444444').grid(row = 2, column = 2)
# Set cau hinh cho nut /
Button_dev = Button(Screen,
padx = 31,
pady = 4,
#bd = 8,
fg = 'white',
font = ('arial', 22, 'bold'),
text = "/",
command=lambda:Button_click("/"),
bg = '#444444').grid(row = 2, column = 3)
# Set cau hinh cho nut 4
Button_4 = Button(Screen,
padx = 24,
#bd = 8,
fg = 'white',
font = ('arial', 25, 'bold'),
text = "4",
command=lambda:Button_click(4),
bg = '#444444').grid(row = 3, column = 0)
# Set cau hinh cho nut 5
Button_5 = Button(Screen,
padx = 24,
#bd = 8,
fg = 'white',
font = ('arial', 25, 'bold'),
text = "5",
command=lambda:Button_click(5),
bg = '#444444').grid(row = 3, column = 1)
# Set cau hinh cho nut 6
Button_6 = Button(Screen,
padx = 24,
#bd = 8,
fg = 'white',
font = ('arial', 25, 'bold'),
text = "6",
command=lambda:Button_click(6),
bg = '#444444').grid(row = 3, column = 2)
# Set cau hinh cho nut *
Button_mul = Button(Screen,
padx = 24,
#bd = 8,
fg = 'white',
font = ('arial', 25, 'bold'),
text = "×",
command=lambda:Button_click("*"),
bg = '#444444').grid(row = 3, column = 3)
# Set cau hinh cho nut 1
Button_1 = Button(Screen,
padx = 24,
#bd = 8,
fg = 'white',
font = ('arial', 25, 'bold'),
text = "1",
command=lambda:Button_click(1),
bg = '#444444').grid(row = 4, column = 0)
# Set cau hinh cho nut 2
Button_2 = Button(Screen,
padx = 24,
#bd = 8,
fg = 'white',
font = ('arial', 25, 'bold'),
text = "2",
command=lambda:Button_click(2),
bg = '#444444').grid(row = 4, column = 1)
# Set cau hinh cho nut 3
Button_3 = Button(Screen,
padx = 24,
#bd = 8,
fg = 'white',
font = ('arial', 25, 'bold'),
text = "3",
command=lambda:Button_click(3),
bg = '#444444').grid(row = 4, column = 2)
# Set cau hinh cho nut -
Button_sub = Button(Screen,
padx = 30,
pady = 4,
#bd = 8,
fg = 'white',
font = ('arial', 22, 'bold'),
text = "-",
command=lambda:Button_click("-"),
bg = '#444444').grid(row = 4, column = 3)
# Set cau hinh cho nut C
Button_cls = Button(Screen,
padx = 24,
pady = 4,
#bd = 8,
fg = 'white',
font = ('arial', 22, 'bold'),
text = "C",
command = Button_clear,
bg = '#444444').grid(row = 5, column = 0)
# Set cau hinh cho nut .
Button_dot = Button(Screen,
padx = 31,
pady = 4,
#bd = 8,
fg = 'white',
font = ('arial', 22, 'bold'),
text = ".",
command=lambda:Button_click('.'),
bg = '#444444').grid(row = 5, column = 1)
# Set cau hinh cho nut 0
Button_0 = Button(Screen,
padx = 24,
pady = 1,
#bd = 8,
fg = 'white',
font = ('arial', 25, 'bold'),
text = "0",
command=lambda:Button_click(0),
bg = '#444444').grid(row = 5, column = 2)
# Set cau hinh cho nut +
Button_sum = Button(Screen,
padx = 24,
#bd = 8,
fg = 'white',
font = ('arial', 25, 'bold'),
text = "+",
command=lambda:Button_click("+"),
bg = '#444444').grid(row = 5, column = 3)
# Set cau hinh cho nut (
Button_op = Button(Screen,
padx = 30,
pady = 4,
#bd = 8,
fg = 'white',
font = ('arial', 22, 'bold'),
text = "(",
command=lambda:Button_click("("),
bg = '#444444').grid(row = 6, column = 0)
# Set cau hinh cho nut )
Button_cl = Button(Screen,
padx = 30,
pady = 4,
#bd = 8,
fg = 'white',
font = ('arial', 22, 'bold'),
text = ")",
command=lambda:Button_click(")"),
bg = '#444444').grid(row = 6, column = 1)
# Set cau hinh cho nut =
Button_equa = Button(Screen,
padx = 26,
pady = 4,
#bd = 8,
fg = 'white',
font = ('arial', 22, 'bold'),
text = "=",
command = Button_equals,
bg = '#444444').grid(row = 6, column = 2)
# Set cau hinh cho nut ~
Button_1_clear = Button(Screen,
padx = 26,
pady = 4,
#bd = 8,
fg = 'white',
font = ('arial', 22, 'bold'),
text = "~",
command = Button_clear1,
bg = '#444444').grid(row = 6, column = 3)
Screen.mainloop()