【发布时间】:2026-02-10 10:55:02
【问题描述】:
from tkinter import *
from tkinter import messagebox
import mysql.connector
from tkinter import Button
def ok():
name = e1.get()
salary = e2.get()
dob = e3.get()
mysqldb = mysql.connector.connect(host="localhost", user="root", password="", database="sahil")
mycursor = mysqldb.cursor()
try:
sql = "INSERT INTO clients(ID,NAME,SALARY,DOB) VALUES(%s, %s, %s, %s)"
val = (name, salary, dob)
mycursor.execute(sql, val)
mysqldb.commit()
messagebox.showinfo("information", "record inserted succesfully..")
except Exception as e:
print(e)
mysqldb.rollback()
mysqldb.close()
root = Tk()
root.title("client data")
root.geometry("400x400")
global e1
global e2
global e3
Label(root, text="NAME").place(x=10, y=10)
Label(root, text="SALARY").place(x=10, y=40)
Label(root, text="DOB").place(x=10, y=80)
e1 = Entry(root)
e1.place(x=140, y=10)
e2 = Entry(root)
e2.place(x=140, y=40)
e3 = Entry(root)
e3.place(x=140, y=80)
Button(root, text="ADD", command="ok").place(x=10, y=120)
root.mainloop()
【问题讨论】:
-
您好,请将您的问题编辑到此帖子*.com/help/how-to-ask
标签: python database tkinter phpmyadmin