python

Insert Records using Python tkinter mysql

This tutorial will teach you how Insert  the Records using Python and mysql. Establish the database connection.

 

from tkinter import *
from tkinter import messagebox
import mysql.connector

def Ok():
    studname = e1.get()
    coursename = e2.get()
    feee = e3.get()

    mysqldb=mysql.connector.connect(host="localhost",user="root",password="",database="smschool")
    mycursor=mysqldb.cursor()

    try:
       sql = "INSERT INTO record (id,stname,course,fee) VALUES (%s, %s, %s, %s)"
       val = ("",studname,coursename,feee)
       mycursor.execute(sql, val)
       mysqldb.commit()
       messagebox.showinfo("information", "Record inserted successfully...")


    except Exception as e:

       print(e)
       mysqldb.rollback()
       mysqldb.close()

root = Tk()
root.title("Student Registation")
root.geometry("300x200")
global e1
global e2
global e3

Label(root, text="Student Name").place(x=10, y=10)
Label(root, text="Course").place(x=10, y=40)
Label(root, text="Fee").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 ,height = 3, width = 13).place(x=10, y=120)


root.mainloop()


i have attached the video link below. which will do this tutorials step by step.

 

admin

Recent Posts

Flexbox: Build Responsive Navigation Bar with HTML & CSS

Introduction to Flexbox When it comes to building responsive layouts, Flexbox offers a powerful and…

2 days ago

Creating Stunning Image Gallery Using CSS Grid

Introduction to CSS Grid The CSS Grid Layout is a powerful tool for creating responsive…

2 days ago

Create Professional Login & Registration Form using HTML & CSS

In this tutorils we are going to teach how to make a attractive Login &…

4 weeks ago

Form Repeater using HTML CSS JQuery

In this tutorial we are going to teach Form Repeater using HTML CSS JQuery.step by…

1 month ago

AJAX CRUD Application in Laravel 11

Introduction to AJAX and Laravel 11 AJAX, which stands for Asynchronous JavaScript and XML which…

1 month ago

C#.net Banking Project: Accurate FD Rate Calculation Tutorial

Introduction to FD Rate Calculation In any banking project, accurately calculating Fixed Deposit (FD) rates…

1 month ago