sign up form using tkinter and os gui

Solutions on MaxInterview for sign up form using tkinter and os gui by the best coders in the world

showing results for - "sign up form using tkinter and os gui"
Keeley
22 Sep 2020
1#import modules
2
3from tkinter import *
4import os
5
6# Designing window for registration
7
8def register():
9    global register_screen
10    register_screen = Toplevel(main_screen)
11    register_screen.title("Register")
12    register_screen.geometry("300x250")
13
14    global username
15    global password
16    global username_entry
17    global password_entry
18    username = StringVar()
19    password = StringVar()
20
21    Label(register_screen, text="Please enter details below", bg="blue").pack()
22    Label(register_screen, text="").pack()
23    username_lable = Label(register_screen, text="Username * ")
24    username_lable.pack()
25    username_entry = Entry(register_screen, textvariable=username)
26    username_entry.pack()
27    password_lable = Label(register_screen, text="Password * ")
28    password_lable.pack()
29    password_entry = Entry(register_screen, textvariable=password, show='*')
30    password_entry.pack()
31    Label(register_screen, text="").pack()
32    Button(register_screen, text="Register", width=10, height=1, bg="blue", command = register_user).pack()
33
34
35# Designing window for login 
36
37def login():
38    global login_screen
39    login_screen = Toplevel(main_screen)
40    login_screen.title("Login")
41    login_screen.geometry("300x250")
42    Label(login_screen, text="Please enter details below to login").pack()
43    Label(login_screen, text="").pack()
44
45    global username_verify
46    global password_verify
47
48    username_verify = StringVar()
49    password_verify = StringVar()
50
51    global username_login_entry
52    global password_login_entry
53
54    Label(login_screen, text="Username * ").pack()
55    username_login_entry = Entry(login_screen, textvariable=username_verify)
56    username_login_entry.pack()
57    Label(login_screen, text="").pack()
58    Label(login_screen, text="Password * ").pack()
59    password_login_entry = Entry(login_screen, textvariable=password_verify, show= '*')
60    password_login_entry.pack()
61    Label(login_screen, text="").pack()
62    Button(login_screen, text="Login", width=10, height=1, command = login_verify).pack()
63
64# Implementing event on register button
65
66def register_user():
67
68    username_info = username.get()
69    password_info = password.get()
70
71    file = open(username_info, "w")
72    file.write(username_info + "\n")
73    file.write(password_info)
74    file.close()
75
76    username_entry.delete(0, END)
77    password_entry.delete(0, END)
78
79    Label(register_screen, text="Registration Success", fg="green", font=("calibri", 11)).pack()
80
81# Implementing event on login button 
82
83def login_verify():
84    username1 = username_verify.get()
85    password1 = password_verify.get()
86    username_login_entry.delete(0, END)
87    password_login_entry.delete(0, END)
88
89    list_of_files = os.listdir()
90    if username1 in list_of_files:
91        file1 = open(username1, "r")
92        verify = file1.read().splitlines()
93        if password1 in verify:
94            login_sucess()
95
96        else:
97            password_not_recognised()
98
99    else:
100        user_not_found()
101
102# Designing popup for login success
103
104def login_sucess():
105    global login_success_screen
106    login_success_screen = Toplevel(login_screen)
107    login_success_screen.title("Success")
108    login_success_screen.geometry("150x100")
109    Label(login_success_screen, text="Login Success").pack()
110    Button(login_success_screen, text="OK", command=delete_login_success).pack()
111
112# Designing popup for login invalid password
113
114def password_not_recognised():
115    global password_not_recog_screen
116    password_not_recog_screen = Toplevel(login_screen)
117    password_not_recog_screen.title("Success")
118    password_not_recog_screen.geometry("150x100")
119    Label(password_not_recog_screen, text="Invalid Password ").pack()
120    Button(password_not_recog_screen, text="OK", command=delete_password_not_recognised).pack()
121
122# Designing popup for user not found
123 
124def user_not_found():
125    global user_not_found_screen
126    user_not_found_screen = Toplevel(login_screen)
127    user_not_found_screen.title("Success")
128    user_not_found_screen.geometry("150x100")
129    Label(user_not_found_screen, text="User Not Found").pack()
130    Button(user_not_found_screen, text="OK", command=delete_user_not_found_screen).pack()
131
132# Deleting popups
133
134def delete_login_success():
135    login_success_screen.destroy()
136
137
138def delete_password_not_recognised():
139    password_not_recog_screen.destroy()
140
141
142def delete_user_not_found_screen():
143    user_not_found_screen.destroy()
144
145
146# Designing Main(first) window
147
148def main_account_screen():
149    global main_screen
150    main_screen = Tk()
151    main_screen.geometry("300x250")
152    main_screen.title("Account Login")
153    Label(text="Select Your Choice", bg="blue", width="300", height="2", font=("Calibri", 13)).pack()
154    Label(text="").pack()
155    Button(text="Login", height="2", width="30", command = login).pack()
156    Label(text="").pack()
157    Button(text="Register", height="2", width="30", command=register).pack()
158
159    main_screen.mainloop()
160
161
162main_account_screen()
163