-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTkinter data 1
More file actions
66 lines (52 loc) · 1.68 KB
/
Copy pathTkinter data 1
File metadata and controls
66 lines (52 loc) · 1.68 KB
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
import tkinter as tk
import mysql.connector
# Connect to the database
db = mysql.connector.connect(
host="host",
user="user",
password="password",
database="database"
)
# Create the main window
root = tk.Tk()
root.title("Login and Registration Form")
# Define functions for login and registration
def login():
# Retrieve the user's input
username = username_entry.get()
password = password_entry.get()
# Verify the user's credentials
cursor = db.cursor()
query = "SELECT * FROM users WHERE username=%s AND password=%s"
cursor.execute(query, (username, password))
# If the user exists, display a success message
if cursor.fetchone():
label = tk.Label(root, text="Login successful")
label.pack()
# If the user does not exist, display an error message
else:
label = tk.Label(root, text="Login failed")
label.pack()
def register():
# Retrieve the user's input
username = username_entry.get()
password = password_entry.get()
# Insert the user's information into the database
cursor = db.cursor()
query = "INSERT INTO users (username, password) VALUES (%s, %s)"
cursor.execute(query, (username, password))
db.commit()
# Display a success message
label = tk.Label(root, text="Registration successful")
label.pack()
# Create the form
username_label = tk.Label(root, text="Username")
username_label.pack()
username_entry = tk.Entry(root)
username_entry.pack()
password_label = tk.Label(root, text="Password")
password_label.pack()
password_entry = tk.Entry(root, show="*")
password_entry.pack()
login_button = tk.Button(root, text="Login", command=login)
login_button.pack()