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

Loginpg Python Code

The document is a Python script for a login screen using Tkinter and MySQL. It includes functions for user login, creating an account, and recovering a password, with error handling for empty fields and incorrect credentials. The GUI components are set up with labels, entry fields, and buttons for user interaction.

Uploaded by

dung.trieu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Loginpg Python Code

The document is a Python script for a login screen using Tkinter and MySQL. It includes functions for user login, creating an account, and recovering a password, with error handling for empty fields and incorrect credentials. The GUI components are set up with labels, entry fields, and buttons for user interaction.

Uploaded by

dung.trieu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

loginpg.

py

from tkinter import *

from tkinter import messagebox

import [Link]

def open_loginscreen():

[Link]()

import loginscreen

[Link]()

def login():

if [Link]() == '' or [Link]() == '':

[Link]('Alert', 'Please enter all entry fields!')

return

# Database connection

mydb = [Link](

host="localhost",

user="root",

password="12345678",

database='p_registration' # Connect to the existing database

cur = [Link]()

query = 'SELECT * FROM personaldata WHERE email = %s AND password = %s'

[Link](query, ([Link](), [Link]()))

role = [Link]()

[Link]()

[Link]()
if role:

[Link]('success', 'Login Successful')

open_loginscreen()

else:

[Link]('Alert!', 'Incorrect email or password')

def forgot_password():

[Link]()

import forgotpassword

[Link]()

def create_account():

[Link]()

import Registration2

[Link]()

window = Tk()

[Link]('Login Screen')

[Link]('490x240+200+200')

[Link](bg='green') # Set background color to black

# Add your login form components here with updated colors

idEntry = Entry(window, width=39, bd=3, bg='white', fg='black')

# Email Label and Entry

email_label = Label(window, text="Email:", fg='white', bg='black', font=('Arial', 12))

email_label.grid(row=0, column=0, padx=10, pady=10)

idEntry = Entry(window, width=30)

[Link](row=0, column=1, padx=10, pady=10)


# Password Label and Entry

password_label = Label(window, text="Password:", fg='white', bg='black', font=('Arial', 12))

password_label.grid(row=1, column=0, padx=10, pady=10)

passwordEntry = Entry(window, width=30, show='*')

[Link](row=1, column=1, padx=10, pady=10)

# Login Button

loginbtn = Button(window, text='LOGIN', command=login)

[Link](row=2, column=1, pady=10)

# Create Account Button

createbtn = Button(window, text='Create Account', command=create_account)

[Link](row=3, column=1, pady=10)

# Forgot Password Button

forgotbtn = Button(window, text='Forgot Password?', command=forgot_password)

[Link](row=4, column=1, pady=10)

[Link]()

#In Python programming, %s is used as a placeholder in strings for string formatting.

#Here's a quick breakdown:

# %s is used to format strings. It tells Python to substitute the %s with a string value.

# %d is used for integers.

# %f is used for floating-point numbers.

# Example 1

# name = "Noureddine"

# age = 30

# print("My name is %s and I am %d years old." % (name, age))


# output: My name is Noureddine and I am 30 years old.

# Example 2

# name = "Noureddine"

# age = 30

# print(f"My name is {name} and I am {age} years old.")

# output: My name is Noureddine and I am 30 years old.

You might also like