0% found this document useful (0 votes)
13 views3 pages

Finals S

This document defines a Python GUI application for user login and logout. It uses the Tkinter module to create a login window with username and password fields. Upon successful login, it generates a random 4-digit OTP and displays a logged in window with the OTP. It also defines a logout function that checks the OTP to log the user out.

Uploaded by

ktdawgkt
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)
13 views3 pages

Finals S

This document defines a Python GUI application for user login and logout. It uses the Tkinter module to create a login window with username and password fields. Upon successful login, it generates a random 4-digit OTP and displays a logged in window with the OTP. It also defines a logout function that checks the OTP to log the user out.

Uploaded by

ktdawgkt
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/ 3

import tkinter

from tkinter import messagebox


import datetime
import random

OTP = "".join([str(random.randint(0, 9)) for x in range(0, 4)])

window = tkinter.Tk()
window.title ("Login form")
window.geometry ('340x440')
window.configure (bg='#333333')

def login():
username = "admin"
password = "admin1"
if username_entry.get() in username:
if username_entry.get() == username and password_entry.get() == password:
loggedInWindow = tkinter.Toplevel(window)
loggedInWindow.config(bg="#333333")
welcomeLabel = tkinter.Label(loggedInWindow, text="Welcome, User",
bg='#333333', fg="#808080", font=("Arial", 14))
timeInLabel = tkinter.Label(loggedInWindow, text=f'Time in:
{datetime.date.today()}, at {datetime.datetime.now().strftime("%H:%M:%S")}',
bg='#333333', fg="#808080", font=("Arial", 14))
OTPLabel = tkinter.Label(loggedInWindow, text=f'Your session\'s OTP is:
{OTP}', bg='#333333', fg="#808080", font=("Arial", 14))
welcomeLabel.grid(row=0,column=0)
OTPLabel.grid(row=1,column=0)
timeInLabel.grid(row=2,column=0)
#messagebox.showinfo(title="Login Success", message="Welcome,you have
successfully logged into your account.")

#messagebox.showinfo(title="Remember your OTP to Time out.: ",


message=OTP)
else:
messagebox.showerror(title="Login Failed", message="Account not found")
else:
messagebox.showerror(title="Login Failed", message="Incorrect password")

frame = tkinter.Frame (bg='#333333')

login_label = tkinter.Label (
frame, text="Login:", bg='#333333', fg="#808080", font=("Arial", 30))
username_label = tkinter.Label (
frame, text="Username:", bg='#333333', fg="#808080", font=("Arial", 14))
username_entry = tkinter.Entry (frame, font=("Arial", 14))
password_entry = tkinter.Entry (frame, show="•", font=("Arial", 14))
password_label = tkinter.Label (
frame, text="Password:", bg='#333333', fg="#808080", font=("Arial", 14))
login_button = tkinter.Button (
frame, text="Login", bg="#000000", fg="#808080", font=("Arial", 14),
command=login)

# Placing widgets on the screen


login_label.grid(row=0, column=0, columnspan=2, sticky="news", pady=40)
username_label.grid(row=1, column=0)
username_entry.grid(row=1, column=1, pady=20)
password_label.grid(row=2, column=0)
password_entry.grid(row=2, column=1, pady=20)
login_button.grid(row=3, column=0, columnspan=2, pady=30)

frame.pack()

def logout():
username = "admin"
VR = OTP
if username_entry.get() == username and VR_entry.get() == OTP:
loggedInWindow = tkinter.Toplevel(window)
loggedInWindow.config(bg="#333333")
welcomeLabel = tkinter.Label(loggedInWindow, text="Welcome, User",
bg='#333333', fg="#808080",
font=("Arial", 14))
timeoutLabel = tkinter.Label(loggedInWindow,
text=f'Time out: {datetime.date.today()}, at
{datetime.datetime.now().strftime("%H:%M:%S")}',
bg='#333333', fg="#808080", font=("Arial", 14))
OTPLabel = tkinter.Label(loggedInWindow, text=f'Your session\'s OTP is:
{OTP}', bg='#333333', fg="#808080",
font=("Arial", 14))
welcomeLabel.grid(row=0, column=0)
timeoutLabel.grid(row=1, column=0)
# messagebox.showinfo(title="Logout Success", message="Welcome,you have
successfully logout your account.")
else:
messagebox.showerror(title="Logout Failed", message="Invalid Log out")

frame = tkinter.Frame(bg='#333333')

# Creating widgets

logout_label = tkinter.Label(
frame, text="Logout:", bg='#333333', fg="#808080", font=("Arial", 30))
username1_label = tkinter.Label(
frame, text="Username:", bg='#333333', fg="#808080", font=("Arial", 14))
username1_entry = tkinter.Entry(frame, font=("Arial", 14))
VR_entry = tkinter.Entry(frame, show="•", font=("Arial", 14))
VR_label = tkinter.Label(
frame, text="VR CODE:", bg='#333333', fg="#808080", font=("Arial", 14))
logout_button = tkinter.Button(
frame, text="Logout", bg="#000000", fg="#808080", font=("Arial", 14),
command=logout)

logout_label.grid(row=0, column=0, columnspan=2, sticky="news", pady=40)


username1_label.grid(row=1, column=0)
username1_entry.grid(row=1, column=1, pady=20)
VR_label.grid(row=2, column=0)
VR_entry.grid(row=2, column=1, pady=20)
logout_button.grid(row=3, column=0, columnspan=2, pady=30)

frame.pack()

window.mainloop()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy