banner



How To Create A Login System In Python

Create login system with background image in tkinter using pythonHello coders, in this post we will learn to create the login system which can be used for user or admin login by using username and password.

Here for example we will set the user name as admin and password as admin123 which will be compared with the entered username and password for successful login.

In this when we click on Log In button by entering correct username and password the login window will be disappeared and the new window will be displayed which contains a button named as Go to Login page, if we click that button then again the login window appears by disappearing the new window.

Modules required:

tkinter: It is used to create Graphical User Interface for the desktop application.

PIL: It is the image processing library used to work with images. Here we will use this module for creating thumbnail and to read the images for using it as a background image in the login window.

Note: The image that you are using for the background should be in same directory where your python file is saved, if it is in the another directory then you have to write the complete path of that image in Image.open().

Installation:

pip install Pillow

Code:

from tkinter import * from tkinter import messagebox from PIL import ImageTk, Image  root = Tk() root.title("Login System") root.resizable(0,0) bg = Image.open('loginbg.png') bg.thumbnail((700, 700)) width, height = bg.size bg = ImageTk.PhotoImage(bg)  def new():     if user_entry.get()=="":         messagebox.showinfo("Login System", "Please enter the Username")     elif password_entry.get()=="":         messagebox.showinfo("Login System", "Please enter the Password")     elif user_entry.get()=="" and password_entry.get()=="":         messagebox.showinfo("Login System", "Please enter the Username and Password")     elif user_entry.get()=="admin" and password_entry.get()=="admin123":         root.withdraw()         paswd.set("")         new_window = Toplevel(root)          def home_page():             new_window.withdraw()             root.deiconify()                      home = Button(new_window, text="Go to Login page", font=("Ariel 22 bold"), relief=GROOVE, bd=2, command=home_page)         home.pack(padx=30, pady=30)     else:         messagebox.showinfo("Login System", "Please enter the correct Username and Password")                   canvas = Canvas(root, width=width, height=height, bd=0, highlightthickness=0) canvas.pack(fill=BOTH, expand=True)  canvas.create_image(0, 0, image=bg, anchor='nw')  label = Label(root, text="Login Page", font=("Ariel 25 bold"), bg='#5500FF', fg='white') canvas.create_window(260, 40, anchor="nw", window=label)  user_label = Label(root, text="User name:", font=("Ariel 18 bold"),bg='#5500FF',fg='white') canvas.create_window(140, 130, anchor="nw", window=user_label)  password_label = Label(root, text="Password:", font=("Ariel 18 bold"),bg='#5500FF',fg='white') canvas.create_window(140, 210, anchor="nw", window=password_label)  user_entry = Entry(root, font=("Ariel 18 bold")) user_entry.focus() canvas.create_window(290, 130, anchor="nw", window=user_entry)  paswd=StringVar() password_entry = Entry(root, textvar=paswd, font=("Ariel 18 bold"), show="*") canvas.create_window(290, 210, anchor="nw", window=password_entry)  login = Button(root, text="Log In", font=("Ariel 22 bold"),                width=8, bg="blue", fg='#FFC331', relief=FLAT, command=new) canvas.create_window(270, 290, anchor="nw", window=login)  root.mainloop()

Image output:

Create login system with background image in tkinter using python

Video output:

So in this way you can create your own applications with the login feature, in addition to this you can use database to save the login information into the database table which can be further used for updating username or password using the update query.

How To Create A Login System In Python

Source: https://www.codershubb.com/create-login-system-with-background-image-in-tkinter-using-python/

Posted by: heatonaned1998.blogspot.com

0 Response to "How To Create A Login System In Python"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel