-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathABus_GUI.py
277 lines (228 loc) · 8.2 KB
/
ABus_GUI.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
# -*- coding: utf-8 -*-
import tkinter as tk
from tkinter import ttk
def Landing_page():
def show():
# global username
print(f"Username = {username.get()}")
# Create the main window
window = tk.Tk()
window.title("ApnaBharat Bus Booking Reservation")
window.geometry("1600x800")
window.resizable(False, False)
# Set the background color to blue
window.configure(bg="#B7C3EC")
# Create a thin ribbon across the top of the window
ribbon = tk.Frame(window, bg="#B1D6C6", height=30)
ribbon.pack(side=tk.TOP, fill=tk.X)
# Add the Welcome text in the middle of the ribbon
welcome_text = tk.Label(
ribbon,
text="ApnaBharat Bus Booking Reservation - Signin/Register to continue",
bg="#B1D6C6",
font=("Calibri Light", 14),
)
welcome_text.place(relx=0.5, rely=0.5, anchor="center")
# Add text on the left edge of the window
edge_text = tk.Label(
window, text="Welcome to ApnaBharat Bus", bg="#B7C3EC", font=("Georgia", 35)
)
edge_text.place(relx=0.5, rely=0.15, anchor="center")
tk.Label(text="Username", bg="#B7C3EC", font=("Calibri", 20)).place(
relx=0.5, rely=0.45, anchor="center"
)
username = tk.StringVar()
# global username
usernm = ttk.Entry(textvariable=username).place(
relx=0.5, rely=0.50, anchor="center", width=250
)
tk.Button(text="Next ➤", command=show, bg="#113870", fg="#B1D6C6").place(
anchor="center", relx=0.5, rely=0.55, height=40, width=100
)
# Run the main loop
window.mainloop()
# ___ Username Login/Register Screen ___
def Login_pswd():
def show():
# global password
print(f"Password = {password.get()}")
# Create the main window
window = tk.Tk()
window.title("ApnaBharat Bus Booking Reservation")
window.geometry("1600x800")
window.resizable(False, False)
# Set the background color to blue
window.configure(bg="#B7C3EC")
# Create a thin ribbon across the top of the window
ribbon = tk.Frame(window, bg="#B1D6C6", height=30)
ribbon.pack(side=tk.TOP, fill=tk.X)
# Add the Welcome text in the middle of the ribbon
welcome_text = tk.Label(
ribbon,
text="ApnaBharat Bus Booking Reservation - Signin/Register to continue",
bg="#B1D6C6",
font=("Calibri Light", 14),
)
welcome_text.place(relx=0.5, rely=0.5, anchor="center")
# Add text on the left edge of the window
edge_text = tk.Label(
window, text="Welcome to ApnaBharat Bus", bg="#B7C3EC", font=("Georgia", 35)
)
edge_text.place(relx=0.5, rely=0.15, anchor="center")
tk.Label(text="Password", bg="#B7C3EC", font=("Calibri", 20)).place(
relx=0.5, rely=0.45, anchor="center"
)
password = tk.StringVar()
# global password
pswd = ttk.Entry(show="*", textvariable=password).place(
relx=0.5, rely=0.51, anchor="center", width=250
)
tk.Button(
text="Login ✔", command=show, bg="#113870", fg="#B1D6C6", font=("Calibri", 12)
).place(anchor="center", relx=0.5, rely=0.58, height=40, width=100)
# Run the main loop
window.mainloop()
# ___Login Password Screen___
def new_usr():
def show():
# global username
# global password
print(f"Username = {username.get()} Password = {password.get()}")
# Create the main window
window = tk.Tk()
window.title("ApnaBharat Bus Booking Reservation")
window.geometry("1600x800")
window.resizable(False, False)
# Set the background color to blue
window.configure(bg="#B7C3EC")
# Create a thin ribbon across the top of the window
ribbon = tk.Frame(window, bg="#B1D6C6", height=30)
ribbon.pack(side=tk.TOP, fill=tk.X)
# Add the Welcome text in the middle of the ribbon
welcome_text = tk.Label(
ribbon,
text="ApnaBharat Bus Booking Reservation - Signin/Register to continue",
bg="#B1D6C6",
font=("Calibri Light", 14),
)
welcome_text.place(relx=0.5, rely=0.5, anchor="center")
# Add text on the left edge of the window
edge_text = tk.Label(
window, text="Welcome to ApnaBharat Bus", bg="#B7C3EC", font=("Georgia", 35)
)
edge_text.place(relx=0.5, rely=0.15, anchor="center")
tk.Label(
text="Hi ___! Register yourself to continue", bg="#B7C3EC", font=("Calibri", 23)
).place(relx=0.5, rely=0.25, anchor="center")
tk.Label(text="Username", bg="#B7C3EC", font=("Calibri", 20)).place(
relx=0.5, rely=0.35, anchor="center"
)
username = tk.StringVar()
# global username
usrnm = ttk.Entry(textvariable=username).place(
relx=0.5, rely=0.40, anchor="center", width=250
)
tk.Label(text="Password", bg="#B7C3EC", font=("Calibri", 20)).place(
relx=0.5, rely=0.50, anchor="center"
)
password = tk.StringVar()
# global password
pswd = ttk.Entry(show="*", textvariable=password).place(
relx=0.5, rely=0.55, anchor="center", width=250
)
tk.Label(text="Confirm Password", bg="#B7C3EC", font=("Calibri", 20)).place(
relx=0.5, rely=0.65, anchor="center"
)
cnfpassword = ttk.Entry(show="*").place(
relx=0.5, rely=0.70, anchor="center", width=250
)
tk.Button(
text="Register and Login ✔",
command=show,
bg="#113870",
fg="#B1D6C6",
font=("Calibri", 12),
).place(anchor="center", relx=0.5, rely=0.75, height=40, width=200)
# Run the main loop
window.mainloop()
# ___ RDBMS MODULE ____
# __Data Storage and retrieval module below__
import mysql.connector as sql_conn
import tkinter as tk
from tkinter import ttk
def infobox(val):
infobox = tk.Tk()
infobox.geometry("800x600+100+100")
infobox.configure(bg="#B7C3EC")
infobox.resizable(False, False)
infobox.title("--Info--")
tk.Label(text=val, bg="#B7C3EC", font=("Calibri", 20)).place(
relx=0.5, rely=0.35, anchor="center"
)
tk.Button(
text="Ok ✔",
command=infobox.destroy,
bg="#113870",
fg="#B1D6C6",
font=("Calibri", 12),
).place(anchor="center", relx=0.5, rely=0.58, height=40, width=100)
infobox.mainloop()
def mysql_pass():
infobox = tk.Tk()
infobox.geometry("800x600+100+100")
infobox.configure(bg="#B7C3EC")
infobox.resizable(False, False)
infobox.title("--Info--")
tk.Label(
text="Enter MySQL Password (Leave blank if no password set)",
bg="#B7C3EC",
font=("Calibri", 20),
).place(relx=0.5, rely=0.35, anchor="center")
global sql_pass
sql_pass = tk.StringVar()
inpt = ttk.Entry(show="*", textvariable=sql_pass).place(
relx=0.5, rely=0.40, anchor="center", width=250
)
tk.Button(
text="Login ✔",
command=infobox.destroy,
bg="#113870",
fg="#B1D6C6",
font=("Calibri", 12),
).place(anchor="center", relx=0.5, rely=0.58, height=40, width=100)
infobox.mainloop()
return sql_pass.get()
conn_obj = sql_conn.connect(host="localhost", user="root", passwd=mysql_pass())
if conn_obj.is_connected():
infobox("Connection established...")
sql_cursor = conn_obj.cursor()
sql_cursor.execute("CREATE DATABASE IF NOT EXISTS Py_PassCred")
sql_cursor.execute("USE Py_PassCred")
infobox("Py_Pass database created")
table = "CREATE TABLE IF NOT EXISTS passwords_data (SNo INTEGER AUTO_INCREMENT PRIMARY KEY,username VARCHAR(20),password VARCHAR(50))"
sql_cursor.execute(table)
else:
infobox("MySQL connection failed.")
infobox("Please restart app after logging in to your MySQL interface.")
def data_entry(username, password):
"""
Actual insertion of data into RDBMS.
Parameters
----------
username : STRING
.
password : STRING
Returns
-------
None.
"""
cmd = f"INSERT INTO passwords_data (username, password) VALUES ('{username}', '{password}')"
data_entry = cmd
infobox("Storing your credentials...")
try:
sql_cursor.execute(data_entry)
conn_obj.commit()
infobox("Your data was entered.")
except (sql_conn.ProgrammingError, sql_conn.IntegrityError):
err = "Only one password per URL is allowed for data integrity\n Please try again with a unique URL"
infobox(err)