· 4 years ago · Mar 21, 2021, 01:08 AM
1
2
3
4import tkinter as tk
5from tkinter import ttk
6from PIL import Image, ImageTk
7import os
8from tkinter.ttk import *
9from tkinter import messagebox
10
11# First Window
12pim = tk.Tk()
13pim.title('HELO WORLD')
14pim.geometry('1000x900')
15
16# Image display
17load = Image.open("C:/Most used/G&D/Discord1/miniApp-pic.jfif")
18imagetkP = ImageTk.PhotoImage(load)
19img = ttk.Label(pim, image=imagetkP)
20img.Image = imagetkP
21img.place(x=0, y=0)
22
23
24
25# Entry's
26# reg here
27
28regL = ttk.Label(pim, text= 'Register here', foreground='white', background='#253873', font=(30))
29regL.place(x=365, y=5)
30
31def two_trans():
32 #transparency for reg window
33 pim.configure(bg='#253873')
34 pim.wm_attributes("-transparentcolor", "#253873")
35 # Transparency for side window
36 pim.configure(bg= 'purple')
37 pim.wm_attributes("-transparentcolor", 'purple' )
38
39two_trans()
40
41
42#firstname entry and label
43
44Ey1 = ttk.Entry(pim, background='white', justify='left', font=(45))
45Ey1.place(x= 490, y=65, width=250, height= 35)
46
47lEy1 = ttk.Label(pim, text= 'firstname', background='#243E82', foreground='white', justify='left', font=('Times New Roman', 20))
48lEy1.place(x= 365, y=65)
49
50#lastname entry and label
51
52lastnameE = ttk.Entry(pim, background='white', justify='left', font=(25))
53lastnameE.place(x= 490, y=125, width=250, height= 35)
54
55lastnameL = ttk.Label(pim, text= 'lastname', background='#364799', foreground='white', justify='left', font=('Times New Roman', 20))
56lastnameL.place(x= 365, y=125)
57
58# age label and Entry
59ageS = Spinbox(pim, from_=12, to_=100)
60ageS.place(x= 490, y=185, width=200, height= 29)
61
62ageL = Label(pim, text= 'age', background= '#3855A5', foreground='white', font=('Times New Roman', 19))
63ageL.place(x=365, y=185)
64
65# email label and entry
66
67email = ttk.Label(pim, text= 'email', background='#415AA8', foreground='white', font=('Times New Roman', 20))
68email.place(x=365, y=245)
69
70emailE= ttk.Entry(pim, text='email', background='white', font=(25))
71emailE.place(x=490, y=245, width=260, height= 35)
72
73# username
74usrl = ttk.Label(pim, text='username', foreground='white', background='#576BBE', font=('Times New Roman', 20))
75usrl.place(x=365, y=305)
76
77usrE= ttk.Entry(pim, background='white', font=(25))
78usrE.place(x=490, y=305, width=250, height=35)
79
80
81# password
82passl = ttk.Label(pim, text='password', foreground='white', background='#6674B7', font=('Times New Roman', 20))
83passl.place(x=365, y=365)
84
85passE= ttk.Entry(pim, background='white', font=(20))
86passE.place(x=490, y=365, width=250, height= 35)
87
88# retype password
89passl = ttk.Label(pim, text='Retype password', foreground='white', background='#8988C2', font=('Times New Roman', 14))
90passl.place(x=352, y=425)
91
92repassE= ttk.Entry(pim, background='white', font=(20))
93repassE.place(x=490, y=425, width=250, height= 35)
94
95
96
97# A button and a Function
98
99def save_Alldata():
100 textInEy1 = Ey1.get().strip()
101 textInEy2 = lastnameE.get().strip()
102 textInEy3 = ageS.get().strip()
103 textInEy4 = emailE.get().strip()
104 textInEy5 = usrE.get().strip()
105 textInEy6 = passE.get().strip()
106 textInEy7 = repassE.get().strip()
107
108 #Writing the data to a txt file
109 if textInEy1:
110 op = open('futuredatabase.txt', 'a+')
111
112 op.write('\n')
113 op.write(textInEy1)
114 op.write('\n')
115
116 op.write('\n')
117 op.write(textInEy2)
118
119
120 op.write('\n')
121 op.write(textInEy3)
122
123
124 op.write('\n')
125 op.write(textInEy4)
126
127
128 op.write('\n')
129 op.write(textInEy5)
130
131
132 op.write('\n')
133 op.write(textInEy6)
134
135
136 op.write('\n')
137 op.write(textInEy7)
138 op.close()
139
140 #deleting the entry.
141 Ey1.delete(0, 'end')
142 lastnameE.delete(0, 'end')
143 ageS.delete(0, 'end')
144 emailE.delete(0, 'end')
145 usrE.delete(0, 'end')
146 passE.delete(0, 'end')
147 repassE.delete(0, 'end')
148
149 op.close()
150
151# Error if submitting when empty entries
152def emptyEy1():
153 if len(Ey1.get())== 0:
154 Warning = messagebox.showwarning(title="Warning", message="Please enter credentials")
155 Warning.place(x=470, y=65)
156
157 if len(lastnameE.get()) == 0:
158 WarningEy2 = messagebox.showwarning(title="Warning", message="Please enter credentials")
159 WarningEy2.place(x=470, y=65)
160
161 if len(ageS.get()) == 0:
162 WarningEy2 = messagebox.showwarning(title="Warning", message="Please enter credentials")
163 WarningEy2.place(x=470, y=65)
164
165 if len(usrE.get()) == 0:
166 WarningEy2 = messagebox.showwarning(title="Warning", message="Please enter credentials")
167 WarningEy2.place(x=470, y=65)
168
169 #if (emailE.get()) != ['@', 'hotmail', 'yahoo', 'gmail', 'outlook']:
170 #Valid_email = messagebox.showinfo(title="email", message="Please enter a valid emailaddress")
171 #Valid_email.place(x=470, y=65)
172
173
174
175 #else:
176 #(emailE.get()) == [f'{textInEy4}@hotmail.com', f'{textInEy4}@yahoo.com', f'{textInEy4}@gmail.com', f'{textInEy4}@outlook.com']
177 #save_Alldata(), credentials()
178
179
180 if len(passE.get()) == 0:
181 WarningEy2 = messagebox.showwarning(title="Warning", message="Please enter credentials")
182 WarningEy2.place(x=470, y=65)
183
184 if len(repassE.get()) == 0:
185 WarningEy2 = messagebox.showwarning(title="Warning", message="Please enter credentials")
186 WarningEy2.place(x=470, y=65)
187
188 if len(passE.get()) != len(repassE.get()):
189 Matchp = messagebox.showwarning(title="Warning", message="Please enter matching passwords")
190 Matchp.place(x=470, y=65)
191
192
193 else:
194 save_Alldata(), credentials()
195
196
197# A func to the submit button
198def credentials():
199 global creds
200 creds['text'] = 'Your credentials is saved and stored in a database'
201
202creds = ttk.Label(pim, text = "", background = '#6974C1', font=('Times New Roman', 15))
203#pim.wm_attributes("-transparentcolor", '#6974C1' )
204creds.place(x = 400, y= 600)
205
206# All visual buttons in tkinter window here
207
208# A button for closing
209su = ttk.Button(pim, text='Exit', command=pim.destroy)
210su.place(x=650, y=550)
211def is_email_valid(email_string):
212 for suffix in ["@hotmail.com", "@yahoo.com", "@gmail.com", "@outlook.com"]:
213 if email_string.endswith(suffix):
214 return True
215
216 return False
217
218"""
219import re
220def emaildata(is_email_valid):
221 data_for_email = emailE.get()
222 is_email_valid = False # You have not assigne
223 for item in [r'@hotmail.com', r'@yahoo.com', r'@gmail.com', r'@outlook.com']:
224 if re.findall(item, data_for_email):
225 return True
226 if not is_email_valid:
227 messagebox.showinfo(title="email", message="Please enter a valid emailaddress")
228 else:
229 return False
230"""
231
232email_from_form = emailE.get()
233if not is_email_valid(email_from_form):
234 messagebox.showinfo(title="email", message="please enter a valid email address")
235
236
237
238# Submit Button
239# collecting data when hitting sub
240submitB = ttk.Button(
241 pim,
242 text ='Confirm',
243 command= lambda: (
244 emptyEy1(),
245 is_email_valid(email_string)
246
247 )
248)
249submitB.place(x=540, y=550)
250
251
252
253# keep it displayed
254pim.mainloop()
255
256"""
257Second window
258"""
259root = tk.Tk()
260
261# describing the window
262root.geometry("1000x800")
263
264# img label
265load = Image.open("C:/Most used/G&D/Discord1/miniApp-pic.jfif")
266imagetkP = ImageTk.PhotoImage(load)
267
268img = ttk.Label(root, image=imagetkP)
269img.image = imagetkP
270img.place(x=0, y=0)
271
272# Entry' 1
273bean = ttk.Entry(root, justify='left', background="white", font=(45))
274bean.place(x=450, y=200, width=400, height=50)
275
276# Entry' 2
277Sv = ttk.Entry(root, justify='left',background="white", show="*", font=(45))
278Sv.place(x=450, y=300, width=400, height=50)
279
280
281# Saving data
282def save_data():
283 all_text = Sv.get().strip()
284 every = bean.get().strip()
285
286 #Writing the data to a txt file
287 if every:
288 op = open('futuredatabase.txt', 'a+')
289
290 op.write('\n')
291 op.write(every )
292 op.write('\n')
293
294 op.write('\n')
295 op.write(all_text )
296 op.close()
297 #clearing the entry
298 bean.delete(0, 'end')
299 Sv.delete(0, 'end')
300 op.close()
301
302def Nodata():
303 if len(bean.get()) == 0:
304 Passcred = messagebox.showerror(title="Error", message="Please enter credentials")
305 Passcred.place(x=470, y=65)
306
307 if len(Sv.get()) == 0:
308 Passcred = messagebox.showerror(title="Error", message="Please enter credentials")
309 Passcred.place(x=470, y=65)
310 else:
311 mit(), save_data()
312
313# A part of the global statement
314path = ttk.Label(root, text = "", background ='#323550', font = ('Times New Roman', 15))
315root.wm_attributes("-transparentcolor", '#323550' )
316path.place(x = 870, y= 395)
317
318# A func to the submit button
319
320def mit():
321 global aware
322 global path
323 aware['text'] = 'Your credentials is saved and stored in a database'
324
325aware = ttk.Label(root, text = "", background = '#6974C1', font=('Times New Roman', 15))
326#root.wm_attributes("-transparentcolor", '#6974C1' )
327aware.place(x = 300, y= 385)
328
329# Submit button
330# collecting data when hitting sub
331sub = ttk.Button(
332 root,
333 text ='Submit',
334 command= lambda: (
335 Nodata()
336
337 )
338)
339sub.place(x=450, y=355, width=75, height = 22)
340
341# user
342usr = ttk.Label(root, text ='username', background = '#3855A5', foreground = 'white', font=('Times New Roman', 25))
343usr.place(x=300, y= 200)
344
345root.configure(bg ='#3855A5' )
346root.wm_attributes("-transparentcolor", '#3855A5' )
347
348# pasword
349psw = ttk.Label(root, text ='password', background = '#576BBE', foreground = 'white', font = ('Times New Roman', 25))
350psw.place(x=300, y= 300)
351
352# side win
353root.configure(bg= 'red')
354root.wm_attributes("-transparentcolor", 'red' )
355
356# whole win
357root.attributes("-alpha", 0.85)
358
359# Welcome title
360wl = ttk.Label(root, text = ('Welcome to Mountain'), background ='#2C478F', foreground = 'white', font = ('Times New Roman', 35))
361wl.place(x = 300, y = 90 )
362
363# Login
364wl = ttk.Label(root, text = (' Login system'), background ='#213877', foreground = 'white', font = ('Times New Roman', 35))
365wl.place(x = 728, y = 90 )
366
367####-------
368# 'Please prompt ur creds' - title
369pl = tk.Label(root, text= 'Please prompt your credentials down below', background = '#3855A5', foreground = 'white', font=('Times New Roman', 17))
370pl.place(x=300, y=150)
371
372# updating the root
373root.update()
374print(root.winfo_width(), root.winfo_height(), root.winfo_geometry())
375
376root.mainloop()
377
378
379
380#The modes are:
381
382#‘r’ – Python read file. Read mode which is used when the file is only being read
383#‘w’ – Python write file. Write mode which is used to edit and write new information to the file (any existing files with the same name will be erased when this mode is activated)
384#‘a’ – Python append file. Append mode, which is used to add new data to the end of the file; that is new information is automatically amended to the end
385#‘r+’ – Special read and write mode, which is used to handle both actions when working with a file
386
387"""
388okay, in the first one, the second if statement is part of the for loop's block. so it potentially can get run every round of the loop (so 4 times in total). and it is also a part of the first if statement's block, so it only gets run if the re.findall part is true.
389
390the second one is still a part of the for loop, but it is not a part of the first if statement. so it gets run 4 times, regardless of the result of the findall check
391
392the third one is outside the for loop entirely. it only gets run once.
393so which one do you think is correct, in this case?
394remembering that just prior to the for loop is the line is_email_valid = False
395
396"""
397
398""" First one
399 for item in [r'@hotmail.com', r'@yahoo.com', r'@gmail.com', r'@outlook.com']:
400 if re.findall(item, data_for_email):
401 is_email_valid = True
402 if not is_email_valid:
403 messagebox.showinfo(title="email", message="Please enter a valid emailaddress")
404"""
405
406
407""" Second one
408 for item in [r'@hotmail.com', r'@yahoo.com', r'@gmail.com', r'@outlook.com']:
409 if re.findall(item, data_for_email):
410 is_email_valid = True
411 if not is_email_valid:
412 messagebox.showinfo(title="email", message="Please enter a valid emailaddress")
413"""
414
415
416
417""" Third one
418 for item in [r'@hotmail.com', r'@yahoo.com', r'@gmail.com', r'@outlook.com']:
419 if re.findall(item, data_for_email):
420 is_email_valid = True
421 if not is_email_valid:
422 messagebox.showinfo(title="email", message="Please enter a valid emailaddress")
423
424"""