-
Notifications
You must be signed in to change notification settings - Fork 1
/
dictionary.py
296 lines (247 loc) · 12.1 KB
/
dictionary.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
288
289
290
291
292
293
294
295
296
import json
from difflib import get_close_matches
from tkinter import *
import sqlite3
import re
from tkinter import messagebox
from tkinter.messagebox import *
global login__root, name_var, ans1, ans2
def signup():
global signup_root
signup_root = Tk()
login__root.withdraw()
signup_root.configure(bg='black')
app = SignUP(signup_root)
signup_root.mainloop()
def login():
login__root = Toplevel()
signup_root.withdraw()
login__root.configure(bg='black')
app = Login(login__root)
login__root.mainloop()
def dict():
dic__root = Tk()
login__root.withdraw()
# dic__root.configure(bg='black')
app = Dictionary(dic__root)
dic__root.mainloop()
class Login:
def __init__(self, login_root):
self.login_root = login_root
self.login_root.title("LOG IN")
pad = 3
self.login_root.geometry(
"{0}x{1}+0+0".format(self.login_root.winfo_screenwidth() - pad, self.login_root.winfo_screenheight() - pad))
self.label_frame = Frame(self.login_root)
self.label_frame.configure(bg="#111212")
self.label_frame.pack(side='top')
self.login_frame = Frame(self.login_root)
# self.login_frame.configure(bg='white')
self.login_frame.pack(side='top')
# login label
Label(self.label_frame, font=('', 50), fg='#DE5D83', bg='black', text="LOGIN",
anchor="center").grid(row=0, column=1, padx=3, pady=3)
# Email label and entry
self.email_var = StringVar()
self.email_label = Label(self.login_frame, font=('', 20), fg='black', bg='white', text="EMAIL: ",
anchor="center").grid(row=0, column=1, padx=3, pady=3)
self.email_entry = Entry(self.login_frame, fg='black', cursor='ibeam', width=50, bg='white',
textvar=self.email_var)
self.email_entry.grid(row=0, column=2, padx=3, pady=3)
# password label and entry
self.password_var = StringVar()
self.password_label = Label(self.login_frame, font=('', 20), fg='black', bg='white', text="PASSWORD: ",
anchor="center").grid(row=1, column=1, padx=3, pady=3)
self.password_entry = Entry(self.login_frame, fg='black', cursor='ibeam', width=50, bg='white', show='*',
textvar=self.password_var)
self.password_entry.grid(row=1, column=2, padx=3, pady=3)
def login():
global ans2
global ans1
while True:
if self.email_entry.get() == '':
messagebox.showinfo("ERROR", "PLEASE ENTER EMAIL")
ans1 = False
break
else:
email = self.email_entry.get()
ans1 = True
break
while True:
if self.password_entry.get() == '':
messagebox.showinfo("ERROR", "PLEASE ENTER PASSWORD")
ans2 = False
break
else:
password = self.password_entry.get()
ans2 = True
break
if ans1 == True and ans2 == True:
conn = sqlite3.connect('Details.db')
with conn:
cursor = conn.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS Details (name TEXT, email TEXT, password TEXT)')
with conn:
cursor.execute("SELECT email,password FROM Details")
ans = cursor.fetchall()
for i in ans:
if email == i[0]:
if password == i[1]:
showinfo("Message", "LOGIN SUCCESS")
dict()
break
else:
showerror("ERROR", "Enter correct password")
continue
# login button
self.login_button = Button(self.login_frame, text='LOGIN', fg='black', bg='#3FEEE6', height=2, width=15,
command=login).grid(
row=2, column=2, padx=3, pady=3)
# signup button
self.signup_button = Button(self.login_frame, text='SIGNUP', fg='black', bg='#3FEEE6', height=2, width=15,
command=signup).grid(row=2, column=1, padx=3, pady=3)
class SignUP:
def __init__(self, master):
self.master = master
self.master.title("SIGN UP")
pad = 3
self.master.geometry(
"{0}x{1}+0+0".format(self.master.winfo_screenwidth() - pad, self.master.winfo_screenheight() - pad))
self.l_frame = Frame(self.master)
self.l_frame.configure(bg="#111212")
self.l_frame.pack(side='top')
self.log_frame = Frame(self.master)
self.log_frame.configure(bg='white')
self.log_frame.pack(side='top')
# login label
Label(self.l_frame, font=('', 50), fg='#DE5D83', bg='black', text="SIGNUP",
anchor="center").grid(row=0, column=1, padx=3, pady=3)
# NAME label and entry
self.name_var_signup = StringVar()
self.name_label = Label(self.log_frame, font=('', 20), fg='black', bg='white', text="NAME: ",
anchor="center").grid(row=0, column=1, padx=3, pady=3)
self.name_entry = Entry(self.log_frame, width=50, textvar=self.name_var_signup)
self.name_entry.grid(row=0, column=2, padx=3, pady=3)
# EMAIL label and entry
self.email_var = StringVar()
self.email_label = Label(self.log_frame, font=('', 20), fg='black', bg='white', text="EMAIL: ",
anchor="center").grid(row=1, column=1, padx=3, pady=3)
self.email_entry = Entry(self.log_frame, cursor='ibeam', width=50, textvar=self.email_var)
self.email_entry.grid(row=1, column=2, padx=3, pady=3)
# PASSWORD label and entry
self.password_var = StringVar()
self.password_label = Label(self.log_frame, font=('', 20), fg='black', bg='white', text="PASSWORD: ",
anchor="center").grid(row=2, column=1, padx=3, pady=3)
self.password_entry = Entry(self.log_frame, fg='black', cursor='ibeam', width=50, bg='white', show='*',
textvar=self.password_var)
self.password_entry.grid(row=2, column=2, padx=3, pady=3)
def signup_user():
global ans, name, email, password
while True:
if self.name_entry.get() is '':
messagebox.showerror("ERROR", "Please enter name")
break
else:
name = self.name_entry.get()
break
while True:
if self.password_entry.get() is '':
messagebox.showerror("ERROR", "Please enter password")
break
else:
password = self.password_entry.get()
break
while True:
regex = '^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$'
if re.search(regex, self.email_entry.get()):
email = self.email_entry.get()
print(email)
ans = True
break
else:
messagebox.showerror("ERROR", "PLEASE ENTER VALID EMAIL ID")
break
if ans:
conn = sqlite3.connect('Details.db')
with conn:
cursor = conn.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS Details (name TEXT, email TEXT, password TEXT)')
cursor.execute('INSERT INTO Details (name,email,password) '
'VALUES(?,?,?)', (name, email, password))
conn.commit()
messagebox.showinfo("INFO", "SUCCESSFULLY SIGNUP")
self.signup_button = Button(self.log_frame, text='SIGNUP', fg='black', bg='#3FEEE6', height=2, width=15,
command=signup_user).grid(row=3, column=2, padx=3, pady=3)
# login button
self.login_button = Button(self.log_frame, text='LOGIN', fg='black', bg='#3FEEE6', height=2, width=15,
command=login).grid(
row=3, column=1, padx=3, pady=3)
class Dictionary:
def __init__(self, dic_root):
self.dic_root = dic_root
self.dic_root.title("SIGN UP")
pad = 3
self.dic_root.geometry(
"{0}x{1}+0+0".format(self.dic_root.winfo_screenwidth() - pad, self.dic_root.winfo_screenheight() - pad))
self.l_frame = Frame(self.dic_root)
# self.l_frame.configure(bg="#111212")
self.l_frame.pack(side='top')
self.login_frame = Frame(self.dic_root)
# self.log_frame.configure(bg='white')
self.login_frame.pack(side='top')
self.text_frame = Frame(self.dic_root)
self.text_frame.pack(side='top')
# login label
Label(self.l_frame, font=('', 50), fg='#DE5D83', text="DICTIONARY",
anchor="center").grid(row=0, column=1, padx=3, pady=3)
self.search_var = StringVar()
Label(self.login_frame, font=('', 20), fg='black', text="ENTER WORD: ",
anchor="center").grid(row=0, column=1, padx=3, pady=3)
self.search_entry = Entry(self.login_frame, fg='black', cursor='ibeam', width=50, bg='white',
textvar=self.search_var)
self.search_entry.grid(row=0, column=2, padx=3, pady=3)
def clear():
self.search_var.set('')
self.search_result_entry.delete('1.0', END)
self.search_result_entry.insert('1.0', '')
def search():
global search
while True:
if self.search_entry.get() is '':
messagebox.showerror("ERROR", "PLEASE ENTER WORD")
ans = False
break
else:
search = self.search_entry.get()
ans = True
break
if ans:
with open('data.json') as json_file:
global data
data = json.load(json_file)
search = search.lower()
if search in data:
for i in data[search]:
self.search_result_entry.insert(INSERT, '\n' + str(i))
elif len(get_close_matches(search, data.keys())) > 0:
answer = get_close_matches(search, data.keys())[0]
answer1 = messagebox.askquestion("Question", "DO YOU MEAN {}? ".format(answer))
if answer1 == 'yes':
for i in data[answer]:
self.search_result_entry.insert(INSERT, '\n' + str(i))
else:
messagebox.showinfo("INFO", "We are unable to understand your word")
self.search_button = Button(self.login_frame, text="SEARCH", width=12, height=2, command=search)
self.search_button.grid(row=1, column=1, padx=3, pady=3)
# text enter field
self.search_result_entry = Text(self.text_frame, height=30, width=70)
self.search_result_entry.grid(row=1, column=1, padx=10, pady=10)
self.reset_button = Button(self.login_frame, text="RESET", width=12, height=2, command=clear)
self.reset_button.grid(row=1, column=2, padx=3, pady=3)
self.quit_button = Button(self.login_frame, text="QUIT", width=12, height=2, command=quit)
self.quit_button.grid(row=1, column=3, padx=3, pady=3)
if __name__ == '__main__':
login__root = Tk()
login__root.configure(bg='black')
app = Login(login__root)
login__root.mainloop()