-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaccount.py
231 lines (168 loc) · 7.52 KB
/
account.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
from tkinter import *
from tkinter import messagebox as mb
from csv import DictReader
import temp_csv
def account_func(username):
f = open('resources/log_details.csv', 'r')
r = DictReader(f)
l = []
for row in r:
l1 = []
l1.append(row['name'])
l1.append(row['username'])
l1.append(row['password'])
l1.append(row['avatar'])
l.append(l1)
def change_info(arg):
for i in l:
if i[0] == username:
p = i[2]
if cur_pass.get() == p:
req = req_pass.get()
for i in l:
if i[0] == username:
if arg == 'Password':
i[2] = req
elif arg == 'Name':
i[0] = req
elif arg == 'Username':
i[1] = req
elif arg == 'Avatar':
i[-1] = req
ma = ''
ml = []
temp = open('resources/temp.txt','w')
for i in l:
ml.append(','.join(i))
to_w = 'name,username,password,avatar'+'@'+'@'.join(ml)
temp.write(to_w)
temp.close()
temp_csv.change()
name.destroy()
mb.showinfo('Done',f'{arg} Updated.\n Changes Will Appear Next Time You Open The Application.')
else:
mb.showerror('Failed','Password Is Incorrect')
def change_avatar():
def set_av(no):
av.destroy()
no = str(no)
f = open('resources/log_details.csv', 'r')
r = DictReader(f)
l = []
for row in r:
l1 = []
l1.append(row['name'])
l1.append(row['username'])
l1.append(row['password'])
l1.append(row['avatar'])
l.append(l1)
for i in l:
if i[0] == username:
i[-1] = no+'.png'
ma = ''
ml = []
temp = open('resources/temp.txt','w')
for i in l:
ml.append(','.join(i))
to_w = 'name,username,password,avatar'+'@'+'@'.join(ml)
temp.write(to_w)
temp.close()
temp_csv.change()
mb.showinfo('success','Avatar Changed.')
pro.destroy()
av = Toplevel()
av.geometry('400x420')
av.configure(bg='light blue')
Label(av, text='Choose Avatar',bg='light blue',font=('Calibri Light',20,'bold')).grid(row=0,columnspan=3)
img_0 = PhotoImage(file='avatars\\0.png')
Button(av,image=img_0,bg='light blue',bd=0,command=lambda : set_av(0)).grid(row=1,column=0)
img_1 = PhotoImage(file='avatars\\1.png')
Button(av,image=img_1,bg='light blue',bd=0,command=lambda : set_av(1)).grid(row=1,column=1)
img_2 = PhotoImage(file='avatars\\2.png')
Button(av,image=img_2,bg='light blue',bd=0,command=lambda : set_av(2)).grid(row=1,column=2)
img_3 = PhotoImage(file='avatars\\3.png')
Button(av,image=img_3,bg='light blue',bd=0,command=lambda : set_av(3)).grid(row=2,column=0)
img_4 = PhotoImage(file='avatars\\4.png')
Button(av,image=img_4,bg='light blue',bd=0,command=lambda : set_av(4)).grid(row=2,column=1)
img_5 = PhotoImage(file='avatars\\5.png')
Button(av,image=img_5,bg='light blue',bd=0,command=lambda : set_av(5)).grid(row=2,column=2)
img_6 = PhotoImage(file='avatars\\6.png')
Button(av,image=img_6,bg='light blue',bd=0,command=lambda : set_av(6)).grid(row=3,column=0)
img_7 = PhotoImage(file='avatars\\7.png')
Button(av,image=img_7,bg='light blue',bd=0,command=lambda : set_av(7)).grid(row=3,column=1)
img_8 = PhotoImage(file='avatars\\8.png')
Button(av,image=img_8,bg='light blue',bd=0,command=lambda : set_av(8)).grid(row=3,column=2)
av.mainloop()
def del_func():
res = mb.askquestion('Confirm', 'Are You Sure That You Want To Delete Your Account.',icon='error')
if res == 'yes':
c.execute(f'delete from log_details where name = "{username}"')
db.commit()
pro.destroy()
def name_func(arg):
global name
name = Tk()
name.geometry('250x200')
name.title(f'Change {arg}')
name.configure(bg='light blue')
Label(name, text=f'Change {arg}',font=('Calibri Light',20,'bold'),bg='light blue').pack()
Label(name, text='Enter Your Current Password.',font=('Calibri Light',13),bg='light blue').place(x=5,y=40)
global cur_pass
cur_pass = Entry(name,font=('Calibri Light',10,'bold'),show='*')
cur_pass.place(x=5,y=70)
Label(name, text=f'Enter {arg} You Want To Set.',font=('Calibri Light',13),bg='light blue').place(x=5,y=100)
global req_pass
req_pass = Entry(name,font=('Calibri Light',10,'bold'))
req_pass.place(x=5,y=130)
Button(name, text='Apply Changes',bd=0,bg='White',fg='black',font=('Calibri Light',10,'bold'),command=lambda:change_info(arg)).place(x=50,y=170)
pro = Toplevel()
pro.geometry('325x425')
pro.title('Profile')
pro.configure(bg='light blue')
f = open('resources/log_details.csv', 'r')
r = DictReader(f)
l = []
for row in r:
l1 = []
l1.append(row['name'])
l1.append(row['username'])
l1.append(row['password'])
l1.append(row['avatar'])
l.append(l1)
for i in l:
if i[0] == username:
if i[-1] == None:
avar_no = '4.png'
break
else:
avar_no = i[-1]
break
avatar = PhotoImage(file=f'avatars\\{avar_no}')
av_button = Button(pro, image=avatar,bg='light blue',bd=0,command=change_avatar)
av_button.place(x=110,y=30)
f = open('resources/log_details.csv', 'r')
r = DictReader(f)
l = []
for row in r:
l1 = []
l1.append(row['name'])
l1.append(row['username'])
l1.append(row['password'])
l.append(l1)
for i in l:
if i[0] == username:
user = i[1]
pencil = PhotoImage(file='resources\\pencil-edit-button.png')
Label(pro,text='@'+user,font=('Calibri Light',16),bg='light blue').place(x=90,y=170)
Label(pro,text=username.title(),font=('Calibri Light',20,'bold'),bg='light blue').place(x=90,y=140)
Label(pro, text= 'Change Name',font=('Calibri Light',20),bg='light blue').place(x=10,y=220)
Button(pro, image=pencil,bg='light blue',bd=0,command=lambda : name_func('Name')).place(x=280,y=220)
Label(pro, text= 'Change Username',font=('Calibri Light',20),bg='light blue').place(x=10,y=270)
Button(pro, image=pencil,bg='light blue',bd=0,command=lambda : name_func('Username')).place(x=280,y=270)
Label(pro, text= 'Change Password',font=('Calibri Light',20),bg='light blue').place(x=10,y=320)
Button(pro, image=pencil,bg='light blue',bd=0,command=lambda : name_func('Password')).place(x=280,y=320)
Label(pro, text= 'Delete Account',font=('Calibri Light',20),bg='light blue').place(x=10,y=370)
delete = PhotoImage(file='resources\\delete.png')
Button(pro, image=delete,bg='light blue',bd=0,command=del_func).place(x=280,y=370)
pro.mainloop()
#account_func('Hardeep Singh')