Registration2.
py
from tkinter import *
from tkinter import messagebox
import [Link]
def main():
def submit():
# Collecting the user data from entry fields
first_name = firstname_entry.get()
last_name = lastname_entry.get()
email = email_entry.get()
selected_gender = gender_var.get()
country = country_var.get()
username = username_entry.get()
password = password_entry.get()
confirm_password = confirm_password_entry.get()
# Validation of the user input
if not (first_name and last_name and email and selected_gender and country and username
and password):
[Link]('Error', 'All fields are required.')
return
if password != confirm_password:
[Link]('Error', "Passwords don't match.")
return
# Database connection and data insertion logic
mydb = [Link](
host="localhost",
user="root",
password="12345678",
database='p_registration' # Connect to the existing database
mycursor = [Link]()
#[Link]('USE your_database_name') # Replace with your database name
query = 'INSERT INTO personaldata (firstname, lastname, email, gender, country, username,
password) VALUES (%s, %s, %s, %s, %s, %s, %s)'
[Link](query, (first_name, last_name, email, selected_gender, country,
username, password))
[Link]()
#[Link]()
[Link]()
[Link]('Success', 'Registration successful!')
[Link]()
# Assuming [Link] has a main() function to initiate the login screen
import loginpg
[Link]()
window = Tk()
[Link]('Registration')
#[Link](bg='yellow') # Set background color to yellow
#Window Size: you're telling the program to create a window that is 540 pixels wide and 640
pixels tall and Window Position:
#Window Position: The second part of the string, '+200+10', determines where on the screen the
window will be positioned. '+200' sets the horizontal position
#distance from the left edge of the screen), and '+10' sets the vertical position (distance from
the top of the screen).
#Therefore, the window will appear 200 pixels to the right and 10 pixels down from the top left
corner of the screen.
[Link]('540x640+200+10')
# Registration Form Components
firstname_label = Label(window, text="First Name:")
firstname_label.pack()
firstname_entry = Entry(window)
firstname_entry.pack()
lastname_label = Label(window, text="Last Name:")
lastname_label.pack()
lastname_entry = Entry(window)
lastname_entry.pack()
email_label = Label(window, text="Email:")
email_label.pack()
email_entry = Entry(window)
email_entry.pack()
gender_var = StringVar()
gender_label = Label(window, text="Gender:")
gender_label.pack()
Radiobutton(window, text="Male", variable=gender_var, value="Male").pack()
Radiobutton(window, text="Female", variable=gender_var, value="Female").pack()
country_var = StringVar()
country_label = Label(window, text="Country:")
country_label.pack()
country_entry = OptionMenu(window, country_var, "USA", "Canada", "UK", "Australia",
"Others")
country_entry.pack()
username_label = Label(window, text="Username:")
username_label.pack()
username_entry = Entry(window)
username_entry.pack()
password_label = Label(window, text="Password:")
password_label.pack()
password_entry = Entry(window, show="*")
password_entry.pack()
confirm_password_label = Label(window, text="Confirm Password:")
confirm_password_label.pack()
confirm_password_entry = Entry(window, show="*")
confirm_password_entry.pack()
submit_button = Button(window, text="Register", command=submit)
submit_button.pack()
[Link]()
if __name__ == "__main__":
main()