Student Entry Tkinter

Using Python Tkinter GUI registration page may be created and record may be inserted in database making the database connection.

Design Student Registration Page:

a) Design the Window Form

b) Add Control on Windows Form like label , TextField(Entry), Button etc

 

Insert Data on Button Click

a)Call the function on button click and make database connectivity with mysql database .

b) insert the data into database on button click.

c) try the following code and see the output

import tkinter
from tkinter import Entry
import mysql.connector
from tkinter import messagebox
global roll
global name
def ok():
try:
db = mysql.connector.connect(
host="localhost",
user="root",
passwd="",
database="sharp_db")
mycursor = db.cursor()
sql = "insert into student(rollno,name) values (%s,%s)"
messagebox.showinfo("Status", "msg1")
roll="4095"
name="john"
messagebox.showinfo("Status", "msg2")
val=(roll,name)
mycursor.execute(sql, val)
db.commit()
print("inserted")
messagebox.showinfo("Status", "Student Registered")
except:
messagebox.showinfo("Error", "Exception occured")
window = tkinter.Tk()
window.title("Student Registration Page")
tkinter.Label(window, text = "Roll No : ",bg="red",fg="yellow").grid(row=0,column=0)
username=Entry(window).grid(row = 0, column = 4,padx=25)
tkinter.Label(window, text = "Name ",bg="green",fg ="yellow").grid(row=0,column=8,padx=10)
password=tkinter.Entry(window).grid(row=0,column=9,padx=25,pady=25)
button3=tkinter.Button(window, text = "Click",bg="red",fg="yellow",command=ok).grid(row=0,column=12)
window.mainloop()

when we run the above code output is:

Click Here

Video/ C Introduction

Watch video in full size