-
Notifications
You must be signed in to change notification settings - Fork 0
/
student_login.py
66 lines (54 loc) · 2.12 KB
/
student_login.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Import all the required modules
from tkinter import Tk, Label, Entry, Button, messagebox
import sqlite3 as sql
from new_student import new_student
# Create a function to create the login window
def student_login():
# Create the login window
window = Tk()
# Set the title of the login window
window.title("Login")
# Set the size of the login window
window.geometry("600x400")
# Create a label for username
username_label = Label(window, text="Username:")
username_label.place(x=50, y=100)
# Create an entry for username
username_entry = Entry(window, width=20)
username_entry.place(x=200, y=100)
# Create a label for password
password_label = Label(window, text="Password:")
password_label.place(x=50, y=150)
# Create an entry for password
password_entry = Entry(window, width=20)
password_entry.place(x=200, y=150)
# Create a button for login
login_btn = Button(window, text="Login", command=lambda: login(username_entry, password_entry))
login_btn.place(x=200, y=200, width=200)
# Create a button for new user
new_user_btn = Button(window, text="New User", command=new_student)
new_user_btn.place(x=200, y=250, width=200)
# Run the login window
window.mainloop()
# Create a function to login
def login(user, pswd):
# Check if user and password are given
if user and pswd:
# Connect to the database
db = sql.connect(database="student.db")
# Create a cursor
cur = db.cursor()
# Select the username and password from the database
cur.execute(f"SELECT * FROM Student WHERE registration='{user.get()}' AND password='{pswd.get()}'")
# Fetch the data
row = cur.fetchone()
# Check if user is found
if row:
# Show a message
messagebox.showinfo("Login", "Login Successful")
else:
# Show a success message
messagebox.showerror("Login", "Login Failed")
else:
# Show an error message
messagebox.showerror("Error", "Please enter username and password")