0% found this document useful (0 votes)
23 views4 pages

Login Py

The document describes code for a login and registration system using Tkinter. It includes functions for registering a new user, logging in an existing user, and handling different responses like login success, invalid password, or user not found. Main windows and popups are designed to handle the registration and login flows.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

Login Py

The document describes code for a login and registration system using Tkinter. It includes functions for registering a new user, logging in an existing user, and handling different responses like login success, invalid password, or user not found. Main windows and popups are designed to handle the registration and login flows.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

from tkinter import *

import os

# Designing window for registration


def destroyPackWidget(parent):
for e in parent.pack_slaves():
[Link]()
def register():
global root,register_screen

destroyPackWidget(root)
register_screen=root
# register_screen = Toplevel(main_screen)
register_screen.title("Register")
register_screen.geometry("300x250")

global username
global password
global username_entry
global password_entry
username = StringVar()
password = StringVar()

Label(register_screen, text="Please enter the details below", bg="blue").pack()


Label(register_screen, text="").pack()
username_lable = Label(register_screen, text="Username * ")
username_lable.pack()
username_entry = Entry(register_screen, textvariable=username)
username_entry.pack()
password_lable = Label(register_screen, text="Password * ")
password_lable.pack()
password_entry = Entry(register_screen, textvariable=password, show='*')
password_entry.pack()
Label(register_screen, text="").pack()
Button(register_screen, text="Register", width=10, height=1, bg="blue",
command=register_user).pack()

# Designing window for login

def login():
global login_screen
login_screen = Toplevel(main_screen)
login_screen.title("Login")
login_screen.geometry("300x250")
Label(login_screen, text="Please enter details below to login").pack()
Label(login_screen, text="").pack()

global username_verify
global password_verify

username_verify = StringVar()
password_verify = StringVar()

global username_login_entry
global password_login_entry

Label(login_screen, text="Username * ").pack()


username_login_entry = Entry(login_screen, textvariable=username_verify)
username_login_entry.pack()
Label(login_screen, text="").pack()
Label(login_screen, text="Password * ").pack()
password_login_entry = Entry(login_screen, textvariable=password_verify,
show='*')
password_login_entry.pack()
Label(login_screen, text="").pack()
Button(login_screen, text="Login", width=10, height=1,
command=login_verify).pack()

# Implementing event on register button


def btnSucess_Click():
global root
destroyPackWidget(root)
def register_user():
global root,username,password
username_info = [Link]()
password_info = [Link]()
print("abc",username_info,password_info,"xyz")
file = open(username_info, "w")
[Link](username_info + "\n")
[Link](password_info)
[Link]()

username_entry.delete(0, END)
password_entry.delete(0, END)

Label(root, text="Registration Success", fg="green", font=("calibri",


11)).pack()
Button(root,text="Click Here to proceed",command=btnSucess_Click).pack()

# Implementing event on login button

def login_verify():
username1 = username_verify.get()
password1 = password_verify.get()
username_login_entry.delete(0, END)
password_login_entry.delete(0, END)

list_of_files = [Link]()
if username1 in list_of_files:
file1 = open(username1, "r")
verify = [Link]().splitlines()
if password1 in verify:
login_sucess()

else:
password_not_recognised()

else:
user_not_found()

# Designing popup for login success

def login_sucess():
global login_success_screen
login_success_screen = Toplevel(login_screen)
login_success_screen.title("Success")
login_success_screen.geometry("150x100")
Label(login_success_screen, text="Login Success").pack()
Button(login_success_screen, text="OK", command=delete_login_success).pack()

# Designing popup for login invalid password

def password_not_recognised():
global password_not_recog_screen
password_not_recog_screen = Toplevel(login_screen)
password_not_recog_screen.title("Success")
password_not_recog_screen.geometry("150x100")
Label(password_not_recog_screen, text="Invalid Password ").pack()
Button(password_not_recog_screen, text="OK",
command=delete_password_not_recognised).pack()

# Designing popup for user not found

def user_not_found():
global user_not_found_screen
user_not_found_screen = Toplevel(login_screen)
user_not_found_screen.title("Success")
user_not_found_screen.geometry("150x100")
Label(user_not_found_screen, text="User Not Found").pack()
Button(user_not_found_screen, text="OK",
command=delete_user_not_found_screen).pack()

# Deleting popups

def delete_login_success():
login_success_screen.destroy()

def delete_password_not_recognised():
password_not_recog_screen.destroy()

def delete_user_not_found_screen():
user_not_found_screen.destroy()

# Designing Main(first) window

def main_account_screen(frmmain):
main_screen=frmmain

main_screen.geometry("300x250")
main_screen.title("Account Login")
Label(main_screen,text="Select Your Choice", bg="blue", width="300",
height="2", font=("Calibri", 13)).pack()
Label(main_screen,text="").pack()
Button(main_screen,text="Login", height="2", width="30", command=login).pack()
Label(main_screen,text="").pack()
Button(main_screen,text="Register", height="2", width="30",
command=register).pack()

root = Tk()
main_account_screen(root)

[Link]()

You might also like