Hello friends how are you, today in this blog i will teach you how you can create a Login Form in Python using Tkinter GUI Library. This tutorial will help you definitely if you wan to create a window application in Python. I am using PyCharm IDE and now i am going to describe everything step by step so just go through this post to get complete knowledge.
Login form is one of the most used Form in Window or GUI Applications, It helps user to login by using username and password and once the credentials are validated user can get the privilege access.
Here i have created a login form using Tkinter GUI library in which i have used a default username [abcd@gmail.com] and password[abc123] you can change it as per your need.
I have applied a Empty Validation means if you left blank either Username or Password then you will get a message "fill the empty field!!!" after pressing button.
When you will enter wrong Username or Password then you will get a message "wrong username or password!!!" after pressing button.
Widgets used to create Login Form
1.Label
2.TextBox or EditText(Entry)
3.PasswordField
4.Button
Complete Login Form
from tkinter import * #defining login function def login(): #getting form data uname=username.get() pwd=password.get() #applying empty validation if uname=='' or pwd=='': message.set("fill the empty field!!!") else: if uname=="abcd@gmail.com" and pwd=="abc123": message.set("Login success") else: message.set("Wrong username or password!!!") #defining loginform function def Loginform(): global login_screen login_screen = Tk() #Setting title of screen login_screen.title("Login Form") #setting height and width of screen login_screen.geometry("300x250") #declaring variable global message; global username global password username = StringVar() password = StringVar() message=StringVar() #Creating layout of login form Label(login_screen,width="300", text="Please enter details below", bg="orange",fg="white").pack() #Username Label Label(login_screen, text="Username * ").place(x=20,y=40) #Username textbox Entry(login_screen, textvariable=username).place(x=90,y=42) #Password Label Label(login_screen, text="Password * ").place(x=20,y=80) #Password textbox Entry(login_screen, textvariable=password ,show="*").place(x=90,y=82) #Label for displaying login status[success/failed] Label(login_screen, text="",textvariable=message).place(x=95,y=100) #Login button Button(login_screen, text="Login", width=10, height=1, bg="orange",command=login).place(x=105,y=130) login_screen.mainloop() #calling function Loginform Loginform()
1 Comments
After successful login open a new window. How it is write?
ReplyDelete