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
1#how to create simple GUI registration form.
2#importing tkinter module for GUI application
3from tkinter import *
4
5#Creating object 'root' of Tk()
6root = Tk()
7
8#Providing Geometry to the form
9root.geometry("500x500")
10
11#Providing title to the form
12root.title('Registration form')
13
14#this creates 'Label' widget for Registration Form and uses place() method.
15label_0 =Label(root,text="Registration form", width=20,font=("bold",20))
16#place method in tkinter is geometry manager it is used to organize widgets by placing them in specific position
17label_0.place(x=90,y=60)
18
19#this creates 'Label' widget for Fullname and uses place() method.
20label_1 =Label(root,text="FullName", width=20,font=("bold",10))
21label_1.place(x=80,y=130)
22
23#this will accept the input string text from the user.
24entry_1=Entry(root)
25entry_1.place(x=240,y=130)
26
27#this creates 'Label' widget for Email and uses place() method.
28label_3 =Label(root,text="Email", width=20,font=("bold",10))
29label_3.place(x=68,y=180)
30
31entry_3=Entry(root)
32entry_3.place(x=240,y=180)
33
34#this creates 'Label' widget for Gender and uses place() method.
35label_4 =Label(root,text="Gender", width=20,font=("bold",10))
36label_4.place(x=70,y=230)
37
38
39#the variable 'var' mentioned here holds Integer Value, by deault 0
40var=IntVar()
41
42#this creates 'Radio button' widget and uses place() method
43Radiobutton(root,text="Male",padx= 5, variable= var, value=1).place(x=235,y=230)
44Radiobutton(root,text="Female",padx= 20, variable= var, value=2).place(x=290,y=230)
45
46
47##this creates 'Label' widget for country and uses place() method.
48label_5=Label(root,text="Country",width=20,font=("bold",10))
49label_5.place(x=70,y=280)
50
51#this creates list of countries available in the dropdownlist.
52list_of_country=[ 'India' ,'US' , 'UK' ,'Germany' ,'Austria']
53
54#the variable 'c' mentioned here holds String Value, by default ""
55c=StringVar()
56droplist=OptionMenu(root,c, *list_of_country)
57droplist.config(width=15)
58c.set('Select your Country')
59droplist.place(x=240,y=280)
60
61##this creates 'Label' widget for Language and uses place() method.
62label_6=Label(root,text="Language",width=20,font=('bold',10))
63label_6.place(x=75,y=330)
64
65
66#the variable 'var1' mentioned here holds Integer Value, by default 0
67var1=IntVar()
68#this creates Checkbutton widget and uses place() method.
69Checkbutton(root,text="English", variable=var1).place(x=230,y=330)
70
71
72#the variable 'var2' mentioned here holds Integer Value, by default 0
73var2=IntVar()
74Checkbutton(root,text="German", variable=var2).place(x=290,y=330)
75
76#this creates button for submitting the details provides by the user
77Button(root, text='Submit' , width=20,bg="black",fg='white').place(x=180,y=380)
78
79
80#this will run the mainloop.
81root.mainloop()
82