How to create Login form to check if entered credentials are valid or not.




in this section we will cover how to collect and compare credentials entered by user are valid or not, and displaying a success or mismatch msg based on the same.

username : mandeep.singh
password : aeties

if credentials are matching, application will be as above screen shot, else as below screen shot.




below is the code for the same.


#program

try:
from Tkinter import *
except:
from tkinter import *

user_detail = [
'mandeep.singh', 'aeties']

def display(message):
mb = Tk()
mb.geometry(
'200x50+250+75')
mb.title(
"Aeties_Action")
msg = Label(mb, text=message).pack()
mainloop()

def collect():
a = u_en.get()
b = p_en.get()
if a==user_detail[0]:
if b==user_detail[1]:
display(
'login successfull')
else:
display(
'credentials mismatch')


mw = Tk()

mw.geometry(
"600x100+50+50")
mw.title(
"AETies : Automation Expert Technologies")
mw.config(
background='#eeeeee')

f1 = Frame(mw
, bg='#eeeeee')
f1.pack()

l1 = Label(f1
, text=' Username :\t', bg='#eeeeee').pack(side=LEFT)
u_en = Entry(f1
, width=20)
u_en.pack(
side=LEFT)

f2 = Frame(mw
, bg='#eeeeee')
f2.pack()
l2 = Label(f2
, text=' Password :\t', bg='#eeeeee').pack(side=LEFT)
p_en = Entry(f2
, width=20)
p_en.pack(
side=LEFT)

btn = Button(mw
, text=' Login ', command=collect).pack()

mainloop()




by assigning '*' to option show, we can hide the password value as well.



please refer to design the code for password hiding -> How to hide data entered in Entry Widget.



Comments

My photo
Techno Xpresss
Bangalore, Karnataka, India