-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProto_Stack_GUI.py
More file actions
389 lines (323 loc) · 11.6 KB
/
Proto_Stack_GUI.py
File metadata and controls
389 lines (323 loc) · 11.6 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
import tkinter as t
import random
import smtplib
from os import system
from time import sleep
Path = "E:\\Projects\\CS\\Proto-stack\\Proto-Stack-GUI\\Database.txt"
def destruct_win():
root.destroy()
root4.destroy()
root2.destroy()
root7.destroy()
def otpsender(email):
global x
x = random.randint(4000, 5000)
content = "Hello there,\nYour OTP is " + \
str(x) + "\n\nThank you for using ProtoStack."
server = smtplib.SMTP_SSL("smtp.gmail.com", 465)
server.ehlo()
server.login("protostackportal@gmail.com", "protostack123portal")
server.sendmail("protostackportal@gmail.com", email, content)
server.close()
return x
def logport():
global root7
root7 = t.Tk()
root7.geometry("247x100")
root7.title("WEB PORTAL")
Lb1 = t.Label(root7, text="Stack Implementation",
font=("arial", 16, "bold")).pack()
lb = t.Label(root7, text="Please head towards the command line window",
fg="grey", font=("calibri", 8,)).pack()
but = t.Button(root7, text=" OK ", relief="groove",
command=destruct_win).pack()
root7.mainloop()
print()
print("Lets do some stack implementation.")
print("Welcome..!!")
inp = 1
c = 0
while c == 0:
print("What you want to do?")
print("[1]Enter a stack and perform actions")
print("[2]Auto-generate a stack of your own size")
p = int(input("Enter your choice:"))
sleep(1)
system('cls')
if p == 1:
stack = eval(input("Enter your stack:"))
c = 1
elif p == 2:
size = int(input("Enter the size of stack:"))
stack = auto_stack(size)
print("Stack Generated")
display(stack)
c = 1
else:
print("Invalid input")
continue
while inp != 5:
false_inp = input("Press Enter to continue...")
sleep(1)
system('cls')
print("\n--------------------------")
print("What you want to do??")
print("\n[1]Insert an element on top")
print("[2]Delete an element from top")
print("[3]See the topmost item of your stack")
print("[4]Display your stack")
print("[5]Exit")
print("--------------------------\n")
inp = int(input("Enter your choice:"))
print("\n--------------------------")
sleep(2)
system('cls')
# conditions
if inp == 1:
itm = int(input("Enter the item to be inserted:"))
stack = insert_first_element(stack, itm)
print("--------------------------\n")
elif inp == 2:
if isempty(stack):
print("Stack Underflow")
else:
stack = delete_first_element(stack)
print("--------------------------\n")
elif inp == 3:
if isempty(stack):
print("stack is empty")
else:
print("Topmost Element:", stack[len(stack)-1])
elif inp == 4:
if isempty(stack):
print("stack is empty")
else:
display(stack)
elif inp == 5:
continue
else:
print("invalid input")
sleep(4)
print("\n\nTHANK YOU FOR USING THIS PROGRAM..!!")
i = input("Press Enter to Quit")
def isempty(Stack):
'''Checks if a stack is empty or not'''
if len(Stack) == 0:
return True
else:
return False
def delete_first_element(Stack):
''' Deletes the first element from the stack and returns a new stack'''
g = Stack.pop()
return Stack
def insert_first_element(Stack, element):
'''Inserts an element at the first positon of the stack and returns a new stack'''
Stack.append(element)
return Stack
def auto_stack(size):
'''Creates a random stack from the given size'''
stack = []
for i in range(size):
a = random.randint(0, 9)
stack.append(a)
return stack
def display(Stack):
'''Displays the stack vertically'''
print()
for i in range(len(Stack)-1, -1, -1):
print(Stack[i])
print()
def signup_submit():
global otp
global phone
phone = phone_ent.get()
email = email_ent.get()
global root6
if len(phone) != 10:
phone_mismatch()
else:
root6 = t.Tk()
root6.geometry("300x300")
root6.title("WEB PORTAL")
Lb1 = t.Label(root6, text="OTP Confirmation",
font=("arial", 16, "bold")).pack()
Lb2 = t.Label(root6, text="").pack()
Lb3 = t.Label(
root6, text="An OTP has been sent to your email", font=("arial", 9)).pack()
x = otpsender(email)
Lb3 = t.Label(root6, text="Enter OTP:", font=(
"arial", 9)).place(x=50, y=111)
otp = t.Entry(root6, relief="groove", bd=4)
otp.place(x=120, y=111)
bt = t.Button(root6, text="Validate", relief="groove",
command=otpcheck).place(x=155, y=140)
root6.mainloop()
def otpcheck():
global username
username = username_ent.get()
password = password_ent.get()
otpc = otp.get()
if str(x) == otpc:
f = open(Path, "a")
encryption = username+"#"+password+"#"+"."
f.write(encryption)
f.close()
l = t.Label(root6, text="Registered Successfully",
font=("arial", 9)).place(x=100, y=260)
else:
l = t.Label(root6, text="OTP Registeration Failure",
font=("arial", 9)).place(x=100, y=260)
def submit():
stock_username = entered_username.get()
stock_password = entered_password.get()
if passwordchecker(stock_username, stock_password):
global root4
root4 = t.Tk()
root4.geometry("300x300")
root4.title("WEB PORTAL")
Lb = t.Label(root4, text="Logged in Successfully",
font=("arial", 12, "bold")).pack()
lb = t.Label(root4, text="Click To Continue").place(x=100, y=135)
b = t.Button(root4, text="Continue", relief="groove",
command=logport).place(x=120, y=165)
root4.mainloop()
else:
root5 = t.Tk()
root5.geometry("300x300")
root5.title("WEB PORTAL")
Lb = t.Label(root5, text="Log in Failed",
font=("arial", 12, "bold")).pack()
lb = t.Label(root5, text="Click To try again").place(x=97, y=135)
b = t.Button(root5, text="Retry", relief="groove",
command=login).place(x=125, y=165)
root5.mainloop()
def login():
global entered_username
global entered_password
global root2
entered_username = t.StringVar()
entered_password = t.StringVar()
root2 = t.Tk()
root2.geometry("300x300")
root2.title("WEB PORTAL")
Lb = t.Label(root2, text="Login Page", font=("arial", 16, "bold")).pack()
lb2 = t.Label(root2, text="Enter Your Credentials", font=("arial", 9))
lb3 = t.Label(root2, text="Username:").place(x=50, y=111)
lb2.place(x=83, y=28)
lb3 = t.Label(root2, text="Password:").place(x=50, y=161)
submit_page = t.Button(root2, text="Submit",
relief="groove", command=submit).place(x=130, y=220)
entered_username = t.Entry(root2, relief="groove", bd=4,)
entered_username.place(x=110, y=110)
entered_password = t.Entry(root2, relief="groove", bd=4)
entered_password.place(x=110, y=160)
root2.mainloop()
def phone_mismatch():
root9 = t.Tk()
root9.geometry("247x100")
root9.title("WEB PORTAL")
Lb1 = t.Label(root9, text="Stack Implementation",
font=("arial", 16, "bold")).pack()
lb = t.Label(root9, text="Please enter a valid phone number",
fg="grey", font=("calibri", 8,)).pack()
but = t.Button(root9, text=" OK ", relief="groove",
command=root9.destroy).pack()
root9.mainloop()
def signup():
global root3
root3 = t.Tk()
root3.geometry("300x300")
root3.title("WEB PORTAL")
Lb = t.Label(root3, text="Sign Up Page", font=("arial", 16, "bold")).pack()
lb2 = t.Label(root3, text="Enter Your Required Details", font=("arial", 9))
lb3 = t.Label(root3, text="Username:").place(x=29, y=71)
lb2.place(x=66, y=28)
lb3 = t.Label(root3, text="Phone:").place(x=40, y=100)
lb4 = t.Label(root3, text="E-mail:").place(x=40, y=131)
lb5 = t.Label(root3, text="Password:").place(x=29, y=161)
lb6 = t.Label(root3, text="Confirm:").place(x=35, y=191)
global username_ent
global phone_ent
global email_ent
global password_ent
global cnf_ent
username_ent = t.StringVar()
phone_ent = t.StringVar()
email_ent = t.StringVar()
password_ent = t.StringVar()
cnf_ent = t.StringVar()
username_ent = t.Entry(root3, relief="groove", bd=4)
username_ent.place(x=90, y=71)
phone_ent = t.Entry(root3, relief="groove", bd=4)
phone_ent.place(x=90, y=100)
email_ent = t.Entry(root3, relief="groove", bd=4)
email_ent.place(x=90, y=131)
password_ent = t.Entry(root3, relief="groove", bd=4)
password_ent.place(x=90, y=161)
cnf_ent = t.Entry(root3, relief="groove", bd=4)
cnf_ent.place(x=90, y=191)
submit_page = t.Button(root3, text="Submit", relief="groove",
command=signup_submit).place(x=130, y=230)
root3.mainloop()
def quitroot():
root.quit()
def passwordchecker(username, password):
c = ""
l = ""
o = ""
m = ""
users = []
data_list = []
f = open(Path, "r")
r = f.read()
for i in range(0, len(r)):
if r[i] != ".":
c = c+r[i]
else:
data_list = data_list+[c]
c = ""
continue
for i in range(0, len(data_list)):
o = data_list[i]
for j in range(0, len(o)):
if o[j] != "#":
m = m+o[j]
else:
users = users+[m]
m = ""
o = ""
usernms = []
pswrds = []
for i in range(0, len(users), 2):
usernms = usernms+[users[i]]
for i in range(1, len(users), 2):
pswrds = pswrds+[users[i]]
f.close()
for i in range(0, len(usernms)):
if username == usernms[i]:
if password == pswrds[i]:
return True
else:
return False
# Main
global root
root = t.Tk()
root.geometry("300x300")
root.title("WEB PORTAL")
Lb = t.Label(root, text="Proto-Stack", fg="blue",
font=("Agency FB", 22, "bold")).pack()
Lb2 = t.Label(root, text="This is a Client-Based Portal...",
font=("arial", 9)).pack()
Lb3 = t.Label(root, text="Already Registered?",
font=("arial", 7)).place(x=100, y=90)
button1 = t.Button(root, text="Login", relief="groove", command=login)
button1.place(x=125, y=110)
Lb4 = t.Label(root, text="Don't have an account?",
font=("arial", 7)).place(x=94, y=149)
button2 = t.Button(root, text="Sign Up", relief="groove", command=signup)
button2.place(x=120, y=170)
Lb5 = t.Label(root, text="Click Here To Quit", fg="red",
font=("arial", 7, "underline")).place(x=104, y=240)
button3 = t.Button(root, text="Quit", relief="groove", command=quitroot)
button3.place(x=130, y=260)
root.mainloop()