PYTHON And MySQL - How To Delete Records In MySQL Database Using Python Tkinter

PYTHON - How To Delete Data In MySQL Database In Python Tkinter

Delete Records In MySQL Database Using Python


In this Python Tutorial, we will learn how to delete data from a MySQL database using Python. We will cover the process of removing records from the database to effectively manage and update your data using Python programming language.



Project Source Code:

import tkinter as tk
from tkinter import *
from tkinter import ttk
import mysql.connector

root = Tk()
root.title("Delete Data")

connection = mysql.connector.connect(host='localhost', user='root', password='',
port='3306', database='test_py')
c = connection.cursor()

bkg = "#badc58"


frame = tk.Frame(root, bg=bkg)

label_id = tk.Label(frame, text="ID: ", font=('verdana',12), bg=bkg)
entry_id = tk.Entry(frame, font=('verdana',12))

def deleteData():
user_id = entry_id.get()

delete_query = "DELETE FROM `users_2` WHERE `id` = " + user_id
#vals = (user_id)
c.execute(delete_query)
connection.commit()


button_delete = tk.Button(frame, text="Delete", font=('verdana',14),fg='#ffffff',
bg='red', command = deleteData)

label_id.grid(row=0, column=0)
entry_id.grid(row=0, column=1, pady=10, padx=10)

button_delete.grid(row=1,column=0, columnspan=2, pady=10, padx=10, sticky='nsew')

frame.grid(row=0, column=0)


root.mainloop()


OUTPUT:      
How To Delete Records In MySQL Database Using Python Tkinter







Share this

Related Posts

Previous
Next Post »