-
Notifications
You must be signed in to change notification settings - Fork 5
/
code.py
287 lines (216 loc) · 9.26 KB
/
code.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
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
from tkinter import *
from PIL import ImageTk, Image
import random
window = Tk()
window.title("ATM")
window.resizable(False, False)
# Field keys
atmIdFieldKey = StringVar()
pinFieldKey = StringVar()
# Variables for fields
atmIdText = ""
pinText = ""
# Correct id and pin
correctAtmId = '2020'
correctPin = '6344'
# To keep track of the SCREENS
screenNumber = 0
# Number list
normalList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
shuffledList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
# A global variable to use everywhere
globalList = normalList
# Functions of ENTER button
def pressEnter():
if(screenNumber==0):
goToPage1()
elif(screenNumber==1):
goToPage2()
elif(screenNumber==2):
goToPage3()
elif(screenNumber==3):
window.destroy()
# For creating color and number table
class Table:
def __init__(self, page):
global globalList
random.shuffle(shuffledList)
if(screenNumber==1):
globalList = normalList
elif(screenNumber==2):
globalList = shuffledList
# take the data
lst = [('Red', globalList[0], img1),
('Dark Green', globalList[1], img2),
('Blue', globalList[2], img3),
('Yellow', globalList[3], img4),
('Brown', globalList[4], img5),
('Orange', globalList[5], img6),
('Purple', globalList[6], img7),
('Grey', globalList[7], img8),
('Pink', globalList[8], img9),
('Light Green', globalList[9], img10)]
newFrame = Frame(page, bg='Light blue')
newFrame.grid(columnspan=5)
for i in range(2):
bgColor = ""
for j in range(10):
bgColor = lst[j][0]
lstimg = lst[j][2]
if(i==0):
e = Label(newFrame, height=45, width=45, image=lstimg)
e.grid(row=i, column=j)
else:
e = Text(newFrame, height=2, width=5, fg='Black', font=('Ariel', 10), padx=8, pady=4)
e.grid(row=i, column=j)
e.insert(END, lst[j][i])
# For INTEGER buttons
def pressButton(num):
global atmIdText, pinText
if screenNumber == 1:
atmIdText = atmIdText + str(num)
atmIdFieldKey.set(atmIdText)
elif screenNumber == 2:
pinText = pinText + str(num)
pinFieldKey.set(pinText)
# For CLEAR button
def clearAll():
global atmIdText, pinText
if screenNumber == 1:
atmIdText = ""
atmIdFieldKey.set(atmIdText)
elif screenNumber == 2:
pinText = ""
pinFieldKey.set(pinText)
# For BACKSPACE button
def clearOne():
global atmIdText, pinText
if screenNumber == 1:
atmIdText = atmIdText[:-1]
atmIdFieldKey.set(atmIdText)
elif screenNumber == 2:
pinText = pinText[:-1]
pinFieldKey.set(pinText)
# Main frame
mainFrame = Frame(window, bg='#D4D4D3')
mainFrame.grid(columnspan=5)
# Page 3
def goToPage3():
global globalPageKey, screenNumber
globalPageKey.destroy()
screenNumber = 3
finalText = ''
if ((atmIdText == correctAtmId) and (pinText == correctPin)):
finalText = 'Thank You'
else:
finalText = 'Failed'
page3 = LabelFrame(mainFrame, bg='Light blue')
page3.grid(columnspan=5, ipadx=270, ipady=110, padx=10, pady=10)
globalPageKey = page3
finalText = Label(page3, text=finalText, font=('Courier', 20), bg='Light blue')
finalText.place(relx=0.5, rely=0.35, anchor='center')
def retry():
global atmIdText, pinText
page3.destroy()
atmIdText = ""
atmIdFieldKey.set(atmIdText)
pinText = ""
pinFieldKey.set(pinText)
goToPage1()
if ((atmIdText == correctAtmId) and (pinText == correctPin)):
exitButton = Button(page3, text='Exit', bg='White', height=2, width=8, command=window.destroy)
exitButton.place(relx=0.5, rely=0.65, anchor='center')
else:
retryButton = Button(page3, text='Retry', bg='white', height=2, width=8,command=lambda:retry())
retryButton.place(relx=0.4, rely=0.65, anchor='center')
exitButton = Button(page3, text='Exit', bg='White', height=2, width=8, command=window.destroy)
exitButton.place(relx=0.6, rely=0.65, anchor='center')
# Page 2
def goToPage2():
global globalPageKey, screenNumber
globalPageKey.destroy()
screenNumber = 2
page2 = LabelFrame(mainFrame, bg='Light blue')
page2.grid(columnspan=5, ipady=60, padx=10, pady=10)
globalPageKey = page2
pin = Label(page2, text="PIN", bg='Light blue')
pin.place(relx=0.4, rely=0.6, anchor='center')
pinField = Entry(page2, textvariable=pinFieldKey)
pinField.place(relx=0.6, rely=0.6, anchor='center')
pinSubmit = Button(page2, text='Submit', bg='White', height=2, width=10, command=lambda: goToPage3())
pinSubmit.place(relx=0.5, rely=0.85, anchor='center')
p2 = Table(page2)
# Page 1
def goToPage1():
global globalPageKey, screenNumber
globalPageKey.destroy()
screenNumber = 1
page1 = LabelFrame(mainFrame, bg='Light blue')
page1.grid(columnspan=5, ipady=60, padx=10, pady=10)
globalPageKey = page1
atmId = Label(page1, text="ATM ID", bg='Light blue')
atmId.place(relx=0.4, rely=0.6, anchor='center')
atmIdField = Entry(page1, textvariable=atmIdFieldKey)
atmIdField.place(relx=0.6, rely=0.6, anchor='center')
atmIdSubmit = Button(page1, text='Next', bg='White', height=2, width=10, command=lambda: goToPage2())
atmIdSubmit.place(relx=0.5, rely=0.85, anchor='center')
p1 = Table(page1)
# Page 0
page0 = LabelFrame(mainFrame, bg='Light blue')
page0.grid(columnspan=5, ipadx=270, ipady=110, padx=10, pady=10)
# Assigning a global page to access each page from anywhere
globalPageKey = page0
# Welcome text
welcomeText = Label(page0, text='Welcome to INAXIA bank atm', font=('Courier', 20), bg='Light blue')
welcomeText.place(relx=0.5, rely=0.35, anchor='center')
# Next button
nextbutton = Button(page0, text='Next', bg='White', height=2, width=10, command=lambda: goToPage1())
nextbutton.place(relx=0.5, rely=0.65, anchor='center')
# Full frame for buttons
bottomFrame = Frame(window, bg='#D4D4D3')
bottomFrame.grid(columnspan=5, ipadx=140)
# Frame for fixed buttons
buttonsFrame = LabelFrame(bottomFrame, bg='#AAA9A8')
buttonsFrame.grid(columnspan=5, padx=10, pady=10, sticky='')
bottomFrame.grid_rowconfigure(0, weight=1)
bottomFrame.grid_columnconfigure(0, weight=1)
# Button shapes
img1 = ImageTk.PhotoImage(Image.open("btn1.png"))
img2 = ImageTk.PhotoImage(Image.open("btn2.png"))
img3 = ImageTk.PhotoImage(Image.open("btn3.png"))
img4 = ImageTk.PhotoImage(Image.open("btn4.png"))
img5 = ImageTk.PhotoImage(Image.open("btn5.png"))
img6 = ImageTk.PhotoImage(Image.open("btn6.png"))
img7 = ImageTk.PhotoImage(Image.open("btn7.png"))
img8 = ImageTk.PhotoImage(Image.open("btn8.png"))
img9 = ImageTk.PhotoImage(Image.open("btn9.png"))
img10 = ImageTk.PhotoImage(Image.open("btn10.png"))
# Fixed buttons
button1 = Button(buttonsFrame, image=img1, fg='Black', bg='Black', command=lambda: pressButton(globalList[0]), height=40, width=40)
button1.grid(row=1, column=0, padx=5, pady=5)
button2 = Button(buttonsFrame, image=img2, fg='Black', bg='Black', command=lambda: pressButton(globalList[1]), height=40, width=40)
button2.grid(row=1, column=1, padx=5, pady=5)
button3 = Button(buttonsFrame, image=img3, fg='Black', bg='Black', command=lambda: pressButton(globalList[2]), height=40, width=40)
button3.grid(row=1, column=2, padx=5, pady=5)
button4 = Button(buttonsFrame, image=img4, fg='Black', bg='Black', command=lambda: pressButton(globalList[3]), height=40, width=40)
button4.grid(row=2, column=0, padx=5, pady=5)
button5 = Button(buttonsFrame, image=img5, fg='Black', bg='Black', command=lambda: pressButton(globalList[4]), height=40, width=40)
button5.grid(row=2, column=1, padx=5, pady=5)
button6 = Button(buttonsFrame, image=img6, fg='Black', bg='Black', command=lambda: pressButton(globalList[5]), height=40, width=40)
button6.grid(row=2, column=2, padx=5, pady=5)
button7 = Button(buttonsFrame, image=img7, fg='Black', bg='Black', command=lambda: pressButton(globalList[6]), height=40, width=40)
button7.grid(row=3, column=0, padx=5, pady=5)
button8 = Button(buttonsFrame, image=img8, fg='Black', bg='Black', command=lambda: pressButton(globalList[7]), height=40, width=40)
button8.grid(row=3, column=1, padx=5, pady=5)
button9 = Button(buttonsFrame, image=img9, fg='Black', bg='Black', command=lambda: pressButton(globalList[8]), height=40, width=40)
button9.grid(row=3, column=2, padx=5, pady=5)
button0 = Button(buttonsFrame, image=img10, fg='Black', bg='Black', command=lambda: pressButton(globalList[9]), height=40, width=40)
button0.grid(row=4, column=1, padx=5, pady=5)
backspace = Button(buttonsFrame, text='BACKSPACE', fg='Black', bg='Light grey', command=lambda: clearOne(), height=2, width=10)
backspace.grid(row=1, column=4, padx=5, pady=5)
clear = Button(buttonsFrame, text='CLEAR', fg='Black', bg='Light grey', command=lambda: clearAll(), height=2, width=10)
clear.grid(row=2, column=4, padx=5, pady=5)
enter = Button(buttonsFrame, text='ENTER', fg='Black', bg='Light grey', command=lambda: pressEnter(), height=2, width=10)
enter.grid(row=3, column=4, padx=5, pady=5)
# To open the screen
window.mainloop()