Use the:
import tkinter as tk
from tkinter import messagebox
You can create a login page using the "tkinter" library. It has two entry fields for username and password, and a login button. When the user clicks the login button, the "login()" function is called, which compares the entered username and password with a hardcoded value. If the entered values match, a message is displayed indicating a successful login. Otherwise, an error message is displayed indicating an incorrect username or password.
To create a login system using Python, you would need to store the usernames and passwords in a database or file, and compare the entered values with the stored values. You can use libraries like "sqlite3" or "pymongo" to create a database, or "csv" or "json" libraries to store the data in a file. Here's an example of how to create a login system using "sqlite3".
.............................................................
import sqlite3
from tkinter import messagebox
# create database connection
conn = sqlite3.connect('login.db')
# create table for usernames and passwords
conn.execute('''CREATE TABLE IF NOT EXISTS users
(username TEXT PRIMARY KEY NOT NULL,
password TEXT NOT NULL);''')
# insert some sample data
conn.execute("INSERT INTO users (username, password) VALUES (?, ?)", ('user1', 'password1'))
conn.execute("INSERT INTO users (username, password) VALUES (?, ?)", ('user2', 'password2'))
# create login function
def login():
username = username_entry.get()
password = password_entry.get()
# query database for matching username and password
result = conn.execute("SELECT * FROM users WHERE username = ? AND password = ?", (username, password))
if result.fetchone():
messagebox.showinfo("Login successful", "Welcome, " + username + "!")
else:
messagebox.showerror("Login failed", "Invalid username or password")
# close database connection
conn.close()
.............................................................
This above code creates a database connection using sqlite3, creates a table for usernames and passwords, and inserts some sample data. The login() function queries the database for a matching username and password, and displays a message indicating a successful or failed login. Finally, the database connection is closed.
If you get erro, try install using CMD> pip3 or pip install command.
Youtuber & Creator of iNeed2p YT