import tkinter as tk import mysql.connector # Create a MySQL database connection conn = mysql.connector.connect( host='your_mysql_host', user='your_mysql_user', password='your_mysql_password', database='your_database_name' ) cursor = conn.cursor() # Function to insert data into the database def insert_data(): name = name_entry.get() age = age_entry.get() query = "INSERT INTO mytable (name, age) VALUES (%s, %s)" cursor.execute(query, (name, age)) conn.commit() name_entry.delete(0, tk.END) age_entry.delete(0, tk.END) # Function to delete data from the database def delete_data(): selected_id = id_entry.get() query = "DELETE FROM mytable WHERE id = %s" cursor.execute(query, (selected_id,)) conn.commit() id_entry.delete(0, tk.END) # Function to update data in the database def update_data(): selected_id = id_entry.get() new_age = new_age_entry.get() query = "UPDATE mytable SET age = %s WHERE id = %s" cursor.execute(query, (new_age, selected_id)) conn.commit() id_entry.delete(0, tk.END) new_age_entry.delete(0, tk.END) # Create the GUI window = tk.Tk() window.title('MySQL Database GUI') name_label = tk.Label(window, text='Name:') name_label.pack() name_entry = tk.Entry(window) name_entry.pack() age_label = tk.Label(window, text='Age:') age_label.pack() age_entry = tk.Entry(window) age_entry.pack() insert_button = tk.Button(window, text='Insert Data', command=insert_data) insert_button.pack() id_label = tk.Label(window, text='ID:') id_label.pack() id_entry = tk.Entry(window) id_entry.pack() delete_button = tk.Button(window, text='Delete Data', command=delete_data) delete_button.pack() new_age_label = tk.Label(window, text='New Age:') new_age_label.pack() new_age_entry = tk.Entry(window) new_age_entry.pack() update_button = tk.Button(window, text='Update Age', command=update_data) update_button.pack() window.mainloop()