-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhtml
256 lines (201 loc) · 10 KB
/
html
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
import tkinter as tk
from tkinter import *
from tkinter import ttk
from tkinter.ttk import *
from tkinter import filedialog
from tkinter import messagebox
import mysql.connector
root = Tk()
connection = mysql.connector.connect(host='localhost', user='root', password='12345', database='login')
c = connection.cursor()
# width and height
w = 450
h = 525
# background color
bgcolor = "#0D698B" # Blue Grotto
# Text color
text_color = "#F2F1E8" # Ivory
# ----------- CENTER FORM ------------- #
root.overrideredirect(1) # remove border
ws = root.winfo_screenwidth()
hs = root.winfo_screenheight()
x = (ws - w) / 2
y = (hs - h) / 2
root.geometry("%dx%d+%d+%d" % (w, h, x, y))
# ----------- HEADER ------------- #
headerframe = tk.Frame(root, highlightbackgroun='yellow', highlightcolor='yellow', highlightthickness=2, bg='#E34234', width=w, height=70)
titleframe = tk.Frame(headerframe, bg='#E34234', padx=1, pady=1)
title_label = tk.Label(titleframe, text='Register', padx=20, pady=5, bg='#0D698B', fg='#F2F1E8', font=('Tahoma', 24), width=8)
close_button = tk.Button(headerframe, text='x', borderwidth=1, relief='solid', font=('Verdana', 12))
headerframe.pack()
titleframe.pack()
title_label.pack()
close_button.pack()
titleframe.place(y=26, relx=0.5, anchor=CENTER)
close_button.place(x=410, y=10)
# close window
def close_win():
root.destroy()
close_button['command'] = close_win
# ----------- END HEADER ------------- #
mainframe = tk.Frame(root, width=w, height=h)
# ----------- Login Page ------------- #
loginframe = tk.Frame(mainframe, width=w, height=h)
login_contentframe = tk.Frame(loginframe, padx=30, pady=100,
highlightbackgroun='yellow', highlightcolor='yellow',
highlightthickness=2, bg=bgcolor)
username_label = tk.Label(login_contentframe, text='Username:',
font=('Verdana', 16), bg=bgcolor, fg=text_color)
password_label = tk.Label(login_contentframe, text='Password:',
font=('Verdana', 16), bg=bgcolor, fg=text_color)
username_entry = tk.Entry(login_contentframe, font=('Verdana', 16))
password_entry = tk.Entry(login_contentframe, font=('Verdana', 16), show='*')
login_button = tk.Button(login_contentframe, text="Login", font=('Verdana', 16),
bg='#E34234', fg='#F2F1E8', padx=25, pady=10, width=25)
go_register_label = tk.Label(login_contentframe,
text=">> don't have an account? create one",
font=('Verdana', 10), bg=bgcolor, fg='red')
mainframe.pack(fill='both', expand=1)
loginframe.pack(fill='both', expand=1)
login_contentframe.pack(fill='both', expand=1)
username_label.grid(row=0, column=0, pady=10)
username_entry.grid(row=0, column=1)
password_label.grid(row=1, column=0, pady=10)
password_entry.grid(row=1, column=1)
login_button.grid(row=2, column=0, columnspan=2, pady=40)
go_register_label.grid(row=3, column=0, columnspan=2, pady=20)
# create a function to display the register frame
def go_to_register():
loginframe.forget()
registerframe.pack(fill="both", expand=1)
title_label['text'] = 'Register'
title_label['bg'] = '#E34234'
go_register_label.bind("<Button-1>", lambda page: go_to_register())
# create a function to make the user login
def login():
username = username_entry.get().strip()
password = password_entry.get().strip()
vals = (username, password,)
select_query = "SELECT * FROM `users` WHERE `fullname` = %s and `password` = %s"
c.execute(select_query, vals)
user = c.fetchone()
if user is not None:
#messagebox.showinfo('Test','Test')
import mainform
else:
messagebox.showwarning('Error', 'wrong username or password')
login_button['command'] = login
# ----------- Register Page ------------- #
registerframe = tk.Frame(mainframe, width=w, height=h)
register_contentframe = tk.Frame(registerframe, padx=15, pady=15,
highlightbackgroun='yellow', highlightcolor='yellow',
highlightthickness=2, bg=bgcolor)
fullname_label_rg = tk.Label(register_contentframe, text='Fullname:',
font=('Verdana', 14), bg=bgcolor, fg=text_color)
username_label_rg = tk.Label(register_contentframe, text='Course_Name:',
font=('Verdana', 14), bg=bgcolor, fg=text_color)
password_label_rg = tk.Label(register_contentframe, text='Password:',
font=('Verdana', 14), bg=bgcolor, fg=text_color)
confirmpass_label_rg = tk.Label(register_contentframe, text='Re-Password:',
font=('Verdana', 14), bg=bgcolor, fg=text_color)
phone_label_rg = tk.Label(register_contentframe, text='Time_Slot:',
font=('Verdana', 14), bg=bgcolor, fg=text_color)
gender_label_rg = tk.Label(register_contentframe, text='Gender:',
font=('Verdana', 14), bg=bgcolor, fg=text_color)
image_label_rg = tk.Label(register_contentframe, text='Profile Pic:',
font=('Verdana', 14), bg=bgcolor, fg=text_color)
fullname_entry_rg = tk.Entry(register_contentframe, font=('Verdana', 14), width=22)
username_entry_rg = tk.Entry(register_contentframe, font=('Verdana', 14), width=22)
password_entry_rg = tk.Entry(register_contentframe, font=('Verdana', 14), width=22,
show='*')
confirmpass_entry_rg = tk.Entry(register_contentframe, font=('Verdana', 14), width=22,
show='*')
phone_entry_rg = tk.Entry(register_contentframe, font=('Verdana', 14), width=22)
radiosframe = tk.Frame(register_contentframe)
gender = StringVar()
gender.set('Male')
male_radiobutton = tk.Radiobutton(radiosframe, text='Male', font=('Verdana', 14),
bg=bgcolor, fg=text_color, variable=gender, value='Male')
female_radiobutton = tk.Radiobutton(radiosframe, text='Female', font=('Verdana', 14),
bg=bgcolor, fg=text_color, variable=gender, value='Female')
selectimage_frame = tk.Frame(register_contentframe, bg=bgcolor)
selectimage_button = tk.Button(selectimage_frame, text='select image', bg='#F2F1E8', fg=bgcolor)
imagepath_label_rg = tk.Label(selectimage_frame, text='image path...', bg=bgcolor,
fg=text_color, width=22)
register_button = tk.Button(register_contentframe, text="Register", font=('Verdana', 16),
bg='#E34234', fg='#F2F1E8', padx=25, pady=10, width=25)
go_login_label = tk.Label(register_contentframe,
text=">> already have an account? sign in",
font=('Verdana', 10), bg=bgcolor, fg='red')
register_contentframe.pack(fill='both', expand=1)
fullname_label_rg.grid(row=0, column=0, pady=5, sticky='e')
fullname_entry_rg.grid(row=0, column=1)
username_label_rg.grid(row=1, column=0, pady=5, sticky='e')
username_entry_rg.grid(row=1, column=1)
password_label_rg.grid(row=2, column=0, pady=5, sticky='e')
password_entry_rg.grid(row=2, column=1)
confirmpass_label_rg.grid(row=3, column=0, pady=5, sticky='e')
confirmpass_entry_rg.grid(row=3, column=1)
phone_label_rg.grid(row=4, column=0, pady=5, sticky='e')
phone_entry_rg.grid(row=4, column=1)
gender_label_rg.grid(row=5, column=0, pady=5, sticky='e')
radiosframe.grid(row=5, column=1)
male_radiobutton.grid(row=0, column=0)
female_radiobutton.grid(row=0, column=1)
image_label_rg.grid(row=6, column=0, pady=5, sticky='e')
selectimage_frame.grid(row=6, column=1)
selectimage_button.grid(row=0, column=0, padx=10, pady=10)
imagepath_label_rg.grid(row=0, column=1)
register_button.grid(row=7, column=0, columnspan=2, pady=20)
go_login_label.grid(row=8, column=0, columnspan=2, pady=10)
# create a function to select an image
def select_image():
filename = filedialog.askopenfilename(initialdir='/images',
title="Select Profile Picture",
filetypes=(("png images", "*.png"), ("jpg images", "*.jpg")))
imagepath_label_rg['text'] = filename
selectimage_button['command'] = select_image
# create a function to display the login frame
def go_to_login():
registerframe.forget()
loginframe.pack(fill="both", expand=1)
title_label['text'] = 'Login'
title_label['bg'] = '#E34234'
go_login_label.bind("<Button-1>", lambda page: go_to_login())
# create a function to check if the username already exists
def check_username(username):
username = username_entry_rg.get().strip()
vals = (username,)
select_query = "SELECT * FROM `users` WHERE `fullname` = %s"
c.execute(select_query, vals)
user = c.fetchone()
if user is not None:
return True
else:
return False
# create a function to register a new user
def register():
fullname = fullname_entry_rg.get().strip() # remove white space
username = username_entry_rg.get().strip()
password = password_entry_rg.get().strip()
confirm_password = confirmpass_entry_rg.get().strip()
phone = phone_entry_rg.get().strip()
gdr = gender.get()
imgpath = imagepath_label_rg['text']
if len(fullname) > 0 and len(username) > 0 and len(password) > 0 and len(phone) > 0:
if check_username(username) == False:
if password == confirm_password:
vals = (fullname, username, password, phone, gdr, imgpath)
insert_query = "INSERT INTO `users`(`fullname`, `coursename`, `password`, `timeslot`, `gender`, `image_path`) VALUES (%s,%s,%s,%s,%s,%s)"
c.execute(insert_query, vals)
connection.commit()
messagebox.showinfo('Register', 'your account has been created successfully')
else:
messagebox.showwarning('Password', 'incorrect password confirmation')
else:
messagebox.showwarning('Duplicate Username', 'This Username Already Exists, try another one')
else:
messagebox.showwarning('Empty Fields', 'make sure to enter all the information')
register_button['command'] = register
# ------------------------------------------------------------------------ #
root.mainloop()