
#### End of main window ####
def my_registration():
my_w_child=Toplevel(my_w) # Child window
my_w_child.geometry("300x200") # Size of the window
my_w_child.title("www.plus2net.com")
my_str1 = tk.StringVar()
l1 = tk.Label(my_w_child, textvariable=my_str1 )
l1.grid(row=1,column=2,columnspan=2,sticky='E')
my_str1.set("-Registration--")
my_str = tk.StringVar()
l1 = tk.Label(my_w_child, textvariable=my_str,width=15 )
l1.grid(row=2,column=2)
my_str.set("Name")
name1 = tk.Entry(my_w_child, width=15) # added one Entry box
name1.grid(row=2,column=3)
my_str2 = tk.StringVar()
l2 = tk.Label(my_w_child, textvariable=my_str2 )
l2.grid(row=3,column=2)
my_str2.set("Userid")
userid2 = tk.Entry(my_w_child, width=15) # added one Entry box
userid2.grid(row=3,column=3)
my_str3 = tk.StringVar()
l3 = tk.Label(my_w_child, textvariable=my_str3 )
l3.grid(row=4,column=2)
my_str3.set("Password")
pw3 = tk.Entry(my_w_child, width=15,show='*') # added one Entry box
pw3.grid(row=4,column=3)
b4 = tk.Button(my_w_child, text='Register', command=lambda:add_data())
b4.grid(row=5,column=3)
my_msg = tk.StringVar()
l5 = tk.Label(my_w_child, textvariable=my_msg)
l5.grid(row=6,column=1,columnspan=4,sticky='W')
my_msg.set("Add data")
## layout is over , now adding data to table
def add_data():
flag_validation=True # set the flag
my_name=name1.get() # read name
userid=userid2.get() # read userid
pw=pw3.get() # read password
msg = ""
# validation of entered data
if(len(my_name) <=3): # length of name minimum 4 char
flag_validation=False
msg = msg + "Name minimum 4 char \n "
if(len(pw) <6): # length of password minimum 6 char
flag_validation=False
msg = msg + "password must be minimum 6 char \n "
if(len(userid) <5 or len(userid)>12 or not userid.isalnum()): # userid between 5 and 12
flag_validation=False
msg = msg + "Userid should not be less than 5 \n and more than 12 \n Special chars not allowed "
else:
#my_data=(userid,)
#print(type(my_data))
#my_query="SELECT * FROM mem WHERE userid='" + userid + "'"
my_query="SELECT * FROM mem WHERE userid=%s" #? for sqlite
r_set=my_conn.execute(my_query,userid)
no=len(r_set.fetchall())
if(no>0):
flag_validation=False
msg = msg + "userid exists select different one "
if(flag_validation):
try:
my_msg.set("Adding data...")
my_data1=(my_name,userid,pw)
my_query="INSERT INTO mem(name,userid,password) values(%s,%s,%s)"
curs=my_conn.execute(my_query,my_data1)
#my_conn.commit()
#x=my_conn.execute('''select last_insert_rowid()''')
#id=x.fetchone()
msg="Record added, ID : "+ str(curs.lastrowid)
name1.delete(0,END) # delete the entered text
userid2.delete(0,END) # delete the entered text
pw3.delete(0,END) # delete the entered text
except Exception as e:
print(e)
if(flag_validation):
l5.config(fg='green')
else:
l5.config(fg='red')
my_msg.set(msg)
msg=''
my_w_child.after(3000, lambda: my_msg.set(''))
#### End of Registration process ####
Main Login script
Member Login
Member Listing
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.