How to collect all entered values in registration form.


In addition to How to create a simple registration form, we will taking one step forward and will collect user entered value in a Tuple.

User_Data = (first_name, last_name, email, dob, contact, password)

we are going to collect the data and place then in a tuple user_data according in place as shown above. 


def collect_data():
f_name = name_fn.get()
l_name = name_ln.get()
email = email_e.get()
dob = dd.get() +
'/' + mm.get() + '/' + yy.get()
number = num_e.get()
passwd = pass_p.get()
user_data = f_name
, l_name, email, dob, number, passwd
print("User_Data : ", user_data)

Above is the function designed to collect data from all widgets entered by user and than packing/packaging them as a tuple in line 

 user_data = f_name, l_name, email, dob, number, passwd

here, in this project we are simply collecting data without performing any data validation, like email is in valid format, or password and confirm password is matching or not, or number is valid integer. All these are a next step


After launching our application , we will get the above screen shot window with default values set. Let's edit value and then collect them. below screen shot is with edited values.


above, it is visible that password and confirm section are not matching, as I mentioned earlier that we are doing any validation on data, we are just reading date. We will be reading data entered for Password.

below is the code to call a function collect_data on click of register button


#program
# ********** Registration Form functions **********

def on_click(event):
event.widget.delete(
0, END)


def collect_data():
f_name = name_fn.get()
l_name = name_ln.get()
email = email_e.get()
dob = dd.get() +
'/' + mm.get() + '/' + yy.get()
number = num_e.get()
passwd = pass_p.get()
user_data = f_name
, l_name, email, dob, number, passwd
print("User_Data : ", user_data)



# ********** Registration Form GUI Design **********
try:
from Tkinter import *
except:
from tkinter import *

mw = Tk()

mw.geometry(
"600x400+50+50")
mw.title(
"AETies : Automation Expert Technologies")

hdng = Label(mw
, text='A simple format of REGISTRATION FORM ', fg='blue', pady=10).pack()

# ********** designing name section **********
name_l = Label(mw, text='Name :\t', ).place(x=10, y=50)
name_fn = Entry(mw
, width=22)
name_fn.place(
x=100, y=50)
name_fn.insert(
0,'first name')
name_fn.bind(
"<Button-1>", on_click)
name_ln = Entry(mw
, width=22)
name_ln.place(
x=350, y=50)
name_ln.insert(
0,'last name')
name_ln.bind(
"<Button-1>", on_click)

# ********** designing email section **********
email_l = Label(mw, text='Email :\t', ).place(x=10, y=90)
email_e = Entry(mw
, width=50)
email_e.place(
x=100, y=90)
email_e.insert(
0,'example@example.com')
email_e.bind(
"<Button-1>", on_click)

# ********** designing date of birth section **********
dob_l = Label(mw, text='D.O.B(dd/mm/yyyy) :\t', ).place(x=10, y=130)
dd = Spinbox(mw
, from_=1, to=31, width=3)
dd.place(
x=180, y=130)
mm = Spinbox(mw
, from_=1, to=12, width=3)
mm.place(
x=240, y=130)
yy = Spinbox(mw
, from_=1965, to=2020, width=5)
yy.place(
x=300, y=130)

# ********** designing mobile number entry section **********
num_l = Label(mw, text='Contact No. :\t', ).place(x=10, y=170)
num_e = Entry(mw
, width=50)
num_e.place(
x=100, y=170)
num_e.insert(
0,'01234567890')
num_e.bind(
"<Button-1>", on_click)

# ********** designing create and confirm password entry section **********
pass_l = Label(mw, text='Password:\t', ).place(x=10, y=210)
pass_p = Entry(mw
, width=50)
pass_p.place(
x=100, y=210)
pass_l = Label(mw
, text='Confirm:\t', ).place(x=10, y=250)
pass_c = Entry(mw
, width=50)
pass_c.place(
x=100, y=250)


btn = Button(mw
, text=' register ', fg='blue', command=collect_data).place(x=280, y=300)

mainloop()

 #Output

User_Data : ('Techno', 'Xpresss', 'hello@python.com', '05/08/1990', '9988776655', 'aeties')


you can edit the code to validate data before collection, please refer




Comments

My photo
Techno Xpresss
Bangalore, Karnataka, India