full program with sql
full program with sql
import mysql.connector
root = tk.Tk()
root.geometry("600x400")
label.pack(pady=10)
tk.Label(root, text="Name:").pack(pady=5)
entry_name = tk.Entry(root)
entry_name.pack(pady=5)
entry_roll_no = tk.Entry(root)
entry_roll_no.pack(pady=5)
tk.Label(root, text="Class:").pack(pady=5)
entry_class = tk.Entry(root)
entry_class.pack(pady=5)
entry_dob.pack(pady=5)
tk.Label(root, text="Contact:").pack(pady=5)
entry_contact = tk.Entry(root)
entry_contact.pack(pady=5)
tree.pack(pady=20)
# Define columns
tree.heading("ID", text="ID")
tree.heading("Name", text="Name")
tree.heading("Class", text="Class")
tree.heading("DOB", text="DOB")
tree.heading("Contact", text="Contact")
def add_student():
name = entry_name.get()
roll_no = entry_roll_no.get()
student_class = entry_class.get()
dob = entry_dob.get()
contact = entry_contact.get()
# Connect to MySQL and insert data
db = mysql.connector.connect(
cursor = db.cursor()
cursor.execute(
"INSERT INTO students (name, roll_no, class, dob, contact) VALUES (%s, %s, %s, %s, %s)",
db.commit()
db.close()
entry_name.delete(0, tk.END)
entry_roll_no.delete(0, tk.END)
entry_class.delete(0, tk.END)
entry_dob.delete(0, tk.END)
entry_contact.delete(0, tk.END)
show_students()
def show_students():
tree.delete(row)
cursor = db.cursor()
students = cursor.fetchall()
db.close()
btn_add.pack(pady=10)
show_students()
root.mainloop()