Jovian
⭐️
Sign In
In [16]:
from tkinter import *
from tkinter import ttk
import sqlite3 as sq
import sys
import tkinter.messagebox
from tkinter.filedialog import askopenfilename
from tkinter import ttk
from PIL import Image, ImageTk
from tkcalendar import *
import csv
import tkinter as tk
import ctypes
import time
from time import strftime 

LARGE_FONT= ("Arial", 16)
SMALL_FONT= ("Arial", 12)

class Master(tk.Tk):

    def __init__(self, *args, **kwargs):

        tk.Tk.__init__(self, *args, **kwargs)
        container = tk.Frame(self)
    
        container.pack(side=TOP,fill="both", expand = True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)
        
        self.frames = {}

        for F in (StartPage, PageOne, PageTwo, PageThree, PageFour, PageFive, LogIn,stlogin):

            frame = F(container, self)

            self.frames[F] = frame

            frame.grid(row=0, column=0,sticky=N+S+E+W)
        self.winfo_toplevel().title("By-Mr.Shaktiswarup Pahantasingh")
        self.show_frame(LogIn)
        self.state('zoomed')
    def show_frame(self, cont):

        frame = self.frames[cont]
        frame.tkraise()


class StartPage(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self,parent)
        tk.Frame.configure(self,bg='lawngreen')
#         tk.Label(self,text="",width=30,height=20,bg="#5CDB95",font=("Vineta BT",20,"bold","italic","underline")).pack(side=TOP)
#         tk.label0=tk.Label(self,text="Student Database Management",width=30,height=2,fg='grey25',bg="lawngreen",font=("Vineta BT",20,"bold","italic","underline"))
#         tk.label0.place(relx=0.2,rely=0.0)
        def time(): 
            string = strftime('%H:%M:%S %p :: %d.%m.%y') 
            lbl.config(text = string) 
            lbl.after(1000, time)  
        lbl = Label(self, font = ('calibri',20, 'bold'), 
                    background = 'lawngreen', 
                    foreground = 'grey2',relief=RIDGE)  
        lbl.place(relx=0.0,rely=0.0) 
        time() 
        b1=tk.Button(self,text="Add Record",command=lambda: controller.show_frame(PageOne) )
        b1.place(relx=0.0,rely=0.2,relwidth=0.2)
        b1.config(cursor='mouse',bg='navy', fg='white', bd=8)
        b2=tk.Button(self,text="View Record",command=lambda: controller.show_frame(PageTwo) )
        b2.place(relx=0.0,rely=0.3,relwidth=0.2)
        b2.config(cursor='mouse',bg='navy', fg='white', bd=8)
        b3=tk.Button(self,text="Delete Record",command=lambda: controller.show_frame(PageThree) )
        b3.place(relx=0.0,rely=0.4,relwidth=0.2)
        b3.config(cursor='mouse',bg='navy', fg='white', bd=8)
        b4=tk.Button(self,text="Update Record",command=lambda: controller.show_frame(PageFour) )
        b4.place(relx=0.0,rely=0.5,relwidth=0.2)
        b4.config(cursor='mouse',bg='navy', fg='white', bd=8)
        b5=tk.Button(self,text="Search Record",command=lambda: controller.show_frame(PageFive) )
        b5.place(relx=0.0,rely=0.6,relwidth=0.2)
        b6=tk.Button(self, text="Log Out", command=lambda: controller.show_frame(LogIn))
        b5.config(cursor='mouse',bg='navy', fg='white', bd=8)
        b6.place(relx=0.0,rely=0.7,relwidth=0.2)
        b6.config(cursor='mouse',bg='navy', fg='white', bd=8)
        self.winfo_toplevel().title("Home Page")
        def imgview(self):
            self.img  = Image.open('home3.png')
            self.img = self.img.resize((1090,707)) 
            photo=ImageTk.PhotoImage(self.img)
            self.lab=Label(self,image=photo,relief=SUNKEN)    
            self.img.image=photo
            self.lab.place(relx=0.2,rely=0.0)
        return imgview(self)
class PageOne(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        tk.Frame.configure(self,bg='lawngreen')
        
        
        label0=tk.Label(self,text="Add Student Records Here",fg='grey25',bg="lawngreen",height=1,width=50,)
        label0.place(relx=0.2,rely=0.0)
        label0.config(font=("Vineta BT",12,"bold","italic","underline"))

        e1 = tk.StringVar(self)
        e2 = tk.StringVar(self)
        e3 = tk.StringVar(self)
        e4 = tk.StringVar(self)
        de1= tk.StringVar(self)
        r1 = tk.StringVar(self)
        d  = tk.StringVar(self)
        
        self.label1=tk.Label(self,text="Student Name*",width=20)
        self.label1.place(relx=0.1,rely=0.08)
        self.nentry=tk.Entry(self,textvariable=e1,relief=SOLID)
        self.nentry.place(relx=0.5,rely=0.08,relwidth=0.3)
        
        self.lbl2=tk.Label(self,text="DOB*",width=20)
        self.lbl2.place(relx=0.1,rely=0.14)
        self.ent=DateEntry(self,backgroundcolor="blue",foreground="red",borderwidth=15,textvariable=de1,relief=SOLID)
        self.ent.place(relx=0.5,rely=0.14,relwidth=0.3)
        
        self.label2=tk.Label(self,text="Father's Name*",width=20)
        self.label2.place(relx=0.1,rely=0.21)
        self.fentry=tk.Entry(self,textvariable=e2,relief=SOLID)
        self.fentry.place(relx=0.5,rely=0.21,relwidth=0.3)
        
        self.label3=tk.Label(self,text="Contact No.*",width=20)
        self.label3.place(relx=0.1,rely=0.3)
        self.aentry=tk.Entry(self,textvariable=e3,relief=SOLID)
        self.aentry.place(relx=0.5,rely=0.3,relwidth=0.3)
        
        self.label4=tk.Label(self,text="Student ID*",width=20)
        self.label4.place(relx=0.1,rely=0.4)
        self.identry=tk.Entry(self,textvariable=e4,relief=SOLID)
        self.identry.place(relx=0.5,rely=0.4,relwidth=0.3)
        
        self.label4=tk.Label(self,text="Gender*",width=20)
        self.label4.place(relx=0.1,rely=0.5)
        
        self.radiobutton1=tk.Radiobutton(self,text="male",value='male',var=r1).place(relx=0.5,rely=0.5)
        self.radiobutton2=tk.Radiobutton(self,text="Female",value='female',var=r1).place(relx=0.7,rely=0.5)
        
        self.label4=tk.Label(self,text="Course*",width=20)
        self.label4.place(relx=0.1,rely=0.6)
        
        list1 = ['MBA','MCA','BBA','BCA','BTECH','B-ARCH','BIO-TECH'];
        self.droplist=OptionMenu(self,d, *list1)
        self.droplist.config(width=15)
        d.set('Select Course') 
        self.droplist.place(relx=0.5,rely=0.6,width=200)
        
        self.label5=tk.Label(self,text="Upload Your Photo",width=20)
        self.label5.place(relx=0.1,rely=0.7)
        btn1 = Button(self, text ='import', width=15, command = lambda:OpenFile(self))
        btn1.place(relx=0.5,rely=0.7)
        btn1.config(cursor='mouse',bg='navajoWhite4', fg='white', bd=3)
        def create(self):
            
            deg=e3.get()
            print(deg)
            try:
                x=int(deg) 
            except ValueError:
                tkinter.messagebox.showerror("Invalid","This is not a Num")
            gh=e3.get()
            cn=int(len(str(e3.get())))
            print(cn)
            con = sq.connect('studb.db')
            c = con.cursor()
            if gh == "":             
                tkinter.messagebox.showinfo("Warning", "Please enter your phone num")
            elif cn!=10:
                tkinter.messagebox.showerror("Error", "Phone Num should be 10 Digit")
            elif e1.get() == "":
                tkinter.messagebox.showinfo("Warning", "Please Enter Your Name")
            elif e2.get() == "":
                tkinter.messagebox.showinfo("Warning", "Please Enter Your Fathers Name")
            elif e4.get() == "":
                tkinter.messagebox.showinfo("Warning", "Please Enter Your Roll Num")
            elif de1.get() =="":
                tkinter.messagebox.showinfo("Warning", "Please Enter DOB")
            else:
                try:
                    c.execute('CREATE TABLE IF NOT EXISTS stud2(name TEXT,fname TEXT,phno INTEGER,roll INTEGER UNIQUE,gender TEXT,course TEXT,dob DATESTAMP)') 
                    c.execute('INSERT INTO stud2(name,fname,phno,roll,gender,course,dob) VALUES(?, ?, ?, ?, ?, ?,?)',[e1.get(),e2.get(),e3.get(),e4.get(),r1.get(),d.get(),de1.get()])
                    result=tkinter.messagebox.askyesno("submit","Do you want to submit ?")
                    if result==True:
                        tkinter.messagebox.showinfo("record  submitted","Your data submitted successfully")
                    else:
                        return print('You press No')
                except :
                    tkinter.messagebox.showwarning("Exception","Already Present")
                     
                con.commit()
        def clearData(self):
            self.nentry.delete(0,END)
            self.fentry.delete(0,END)
            self.aentry.delete(0,END)
            self.identry.delete(0,END)
            self.ent.delete(0,END)
            d.set('Select Course')
        
        def OpenFile(self):
            global file
            file = askopenfilename()
            print(file.name)
        def clr(self):
            controller.show_frame(StartPage)
            self.nentry.delete(0,END)
            self.fentry.delete(0,END)
            self.aentry.delete(0,END)
            self.identry.delete(0,END)
            self.ent.delete(0,END)
            d.set('Select Course')
        btnSubmit=Button(self,text="Submit",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda:create(self))
        btnSubmit.place(relx=0.2,rely=0.8,relwidth=0.3)
        btnStartPage=Button(self,text="Back",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda:clr(self) )
        btnStartPage.place(relx=0.5,rely=0.8,relwidth=0.3)
        btnclearData=Button(self,text="Clear Data ",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda:clearData(self) )
        btnclearData.place(relx=0.2,rely=0.9,relwidth=0.3)
        btnquit=Button(self, text="Log Out", command=lambda: controller.show_frame(LogIn))
        btnquit.place(relx=0.5,rely=0.9,relwidth=0.3)
        btnSubmit.config(cursor='mouse',bg='navy', fg='white', bd=5)
        btnStartPage.config(cursor='mouse',bg='navy', fg='white', bd=5)
        btnclearData.config(cursor='mouse',bg='navy', fg='white', bd=5)
        btnquit.config(cursor='mouse',bg='navy', fg='white', bd=5)
        con = sq.connect('studb.db')
        c = con.cursor()
        con.commit()
        
class PageTwo(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        tk.Frame.configure(self,bg='lawngreen')
        label0=tk.Label(self,text="Student Records View Point",fg='grey25',bg="lawngreen",pady=4,width=50,)
        label0.place(relx=0.1,rely=0.0)
        label0.config(font=("Vineta BT",12,"bold","italic","underline"))
        
        def treeview1(self):
            
            con = sq.connect('studb.db')
            c = con.cursor()
            c.execute("SELECT * FROM stud2 ORDER BY roll ASC")
            
            self.tree=ttk.Treeview(self,selectmode='browse')
            vsb = ttk.Scrollbar(self, orient="vertical", command=self.tree.yview)
            vsb.place(relx=0.7,rely=0.1, height=295)
            self.tree.configure(yscrollcommand=vsb.set)
            self.tree["columns"]=("e1","e2","e3","e4","r1","d","de1")
            self.tree.column("#0", width=50, stretch=tk.NO)
            self.tree.column("e1", width=130, stretch=tk.NO)
            self.tree.column("e2", width=155,stretch=tk.NO)
            self.tree.column("e3", width=80, stretch=tk.NO)
            self.tree.column("e4", width=60, stretch=tk.NO)
            self.tree.column("r1", width=60, stretch=tk.NO)
            self.tree.column("d", width=70, stretch=tk.NO)
            self.tree.column("de1", width=85, stretch=tk.NO)
            self.tree.heading("#0",text="ID",anchor=tk.W)
            self.tree.heading("e1", text="NAME",anchor=tk.W)
            self.tree.heading("e2", text="FATHER NAME",anchor=tk.W)
            self.tree.heading("e3", text="PH_No",anchor=tk.W)
            self.tree.heading("e4", text="ROLL No.",anchor=tk.W)
            self.tree.heading("r1", text="GENDER",anchor=tk.W)
            self.tree.heading("d", text="COURSE",anchor=tk.W)
            self.tree.heading("de1", text="DOB",anchor=tk.W)
            style = ttk.Style(self)
            style.theme_use("clam")
            style.configure("Treeview", fieldbackground="gray")
            self.tree.place(relx=0.2,rely=0.1,width=695,height=300)
            index = id = 1
            for row in c:
                self.tree.insert("", index, text=id, values=row)
                index = id = index + 1
            con.commit()
            
        def treeview2(self):
            
            con = sq.connect('studb.db')
            c = con.cursor()
            print(self.d.get())
            var1=self.d.get()
            c.execute("SELECT * FROM stud2  WHERE course = '"+var1+"'")
            
            self.tree=ttk.Treeview(self,selectmode='browse')
            vsb = ttk.Scrollbar(self, orient="vertical", command=self.tree.yview)
            vsb.place(relx=0.7,rely=0.1, height=295)
            self.tree.configure(yscrollcommand=vsb.set)
            self.tree["columns"]=("e1","e2","e3","e4","r1","d","de1")
            self.tree.column("#0", width=50, stretch=tk.NO)
            self.tree.column("e1", width=130, stretch=tk.NO)
            self.tree.column("e2", width=155,stretch=tk.NO)
            self.tree.column("e3", width=80, stretch=tk.NO)
            self.tree.column("e4", width=60, stretch=tk.NO)
            self.tree.column("r1", width=60, stretch=tk.NO)
            self.tree.column("d", width=70, stretch=tk.NO)
            self.tree.column("de1", width=85, stretch=tk.NO)
            self.tree.heading("#0",text="ID",anchor=tk.W)
            self.tree.heading("e1", text="NAME",anchor=tk.W)
            self.tree.heading("e2", text="FATHER NAME",anchor=tk.W)
            self.tree.heading("e3", text="PH_No",anchor=tk.W)
            self.tree.heading("e4", text="ROLL No.",anchor=tk.W)
            self.tree.heading("r1", text="GENDER",anchor=tk.W)
            self.tree.heading("d", text="COURSE",anchor=tk.W)
            self.tree.heading("de1", text="DOB",anchor=tk.W)
            style = ttk.Style(self)
            style.theme_use("clam")
            style.configure("Treeview", fieldbackground="gray")
            self.tree.place(relx=0.2,rely=0.1,width=695,height=300)
            index = id = 1
            for row in c:
                self.tree.insert("", index, text=id, values=row)
                index = id = index + 1
            con.commit()
        def func(self):
            record_course=self.d.get()
            print(record_course)
        self.d=tk.StringVar(self)
        list1 = ['MBA','MCA','BBA','BCA','BTECH','B-ARCH','BIO-TECH'];
        self.dlist=OptionMenu(self,self.d, *list1,command=func(self))
        self.dlist.config(width=15,bg='yellow') 
        self.d.set('Select Course')   
        self.dlist.place(relx=0.5,rely=0.7,relwidth=0.3)
        
        btnvc=tk.Button(self,text="View Student details course wise",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda:treeview2(self))
        btnvc.place(relx=0.18,rely=0.7,relwidth=0.3)
        btnvc.config(cursor='mouse',bg='navy', fg='white', bd=5)
        btnViewRec=tk.Button(self,text="View All Records",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda:treeview1(self) )
        btnViewRec.place(relx=0.18,rely=0.8,relwidth=0.3)
        btnViewRec.config(cursor='mouse',bg='navy', fg='white', bd=5)
        btnStart=tk.Button(self,text="Go to Home Page ",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda: controller.show_frame(StartPage) )
        btnStart.place(relx=0.5,rely=0.8,relwidth=0.3)
        btnStart.config(cursor='mouse',bg='navy', fg='white', bd=5)
        btndel=tk.Button(self,text="Go to Delete Record",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda:controller.show_frame(PageThree) )
        btndel.place(relx=0.5,rely=0.85,relwidth=0.3)
        btndel.config(cursor='mouse',bg='navy', fg='white', bd=5)
        btnupd=tk.Button(self,text="Go to Update Record",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda:controller.show_frame(PageFour) )
        btnupd.place(relx=0.18,rely=0.85,relwidth=0.3)
        btnupd.config(cursor='mouse',bg='navy', fg='white', bd=5)
class PageThree(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        tk.Frame.configure(self,bg='lawngreen')
        label=tk.Label(self,text=" ",bd=12,width=50,height=35,bg="lawngreen",fg="blue",font=("times",12,"bold","italic")).pack()
        label0=tk.Label(self,text="Student Records Delete Point",fg='grey25',bg="lawngreen",pady=4,width=50,)
        label0.place(relx=0.1,rely=0.0)
        label0.config(font=("Vineta BT",15,"bold","italic","underline"))
        
        
        labdelete1=Label(self,text='Give a Roll Num* :',font=('none 13 bold'))
        labdelete1.place(relx=0.3,rely=0.5)
        self.rdelete=Entry(self,width=20,font=('none 13 bold'))
        self.rdelete.place(relx=0.3,rely=0.6)
       
        def delete1(self):    
            print("Record Deleted")
            con = sq.connect('studb.db')
            c = con.cursor()
            z=int(self.rdelete.get())
            dataCopy = c.execute("select count(*) from stud2;")
            values = dataCopy.fetchone()
            print (values[0])
            if z >values[0]:
                tkinter.messagebox.showerror("Error", "No Roll No. Found")

            elif z == "":
                tkinter.messagebox.showinfo("Warning", "Please Enter a Roll num")   
            else:
                
                c.execute("DELETE FROM stud2 WHERE roll = " + self.rdelete.get())
                result1=tkinter.messagebox.askyesno("Delete","Do you want to delete this roll num ?")
                if result1==True:
                    tkinter.messagebox.showinfo("Record Removed","Student record removed successfully")
                else:
                    return print('you press no')
                con.commit()
                
        btndel1=tk.Button(self,text="Dlete Record",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda:delete1(self) )
        btndel1.place(relx=0.3,rely=0.7,relwidth=0.1)
        btndel1.config(cursor='mouse',bg='navy', fg='white', bd=5)
        btnStart=tk.Button(self,text="Go to Home Page ",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda: controller.show_frame(StartPage) )
        btnStart.place(relx=0.3,rely=0.8,relwidth=0.2)
        btnStart.config(cursor='mouse',bg='navy', fg='white', bd=5)
        btnView=tk.Button(self,text="View Records ",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda: controller.show_frame(PageTwo) )
        btnView.place(relx=0.5,rely=0.8,relwidth=0.2)
        btnView.config(cursor='mouse',bg='navy', fg='white', bd=5)


        
    

class PageFour(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        tk.Frame.configure(self,bg='lawngreen')
        
        label0=tk.Label(self,text="Update Student Records Here",fg='grey25',bg="lawngreen",pady=4,width=50,)
        label0.place(relx=0.1,rely=0.0)
        label0.config(font=("Vineta BT",15,"bold","italic","underline"))
        self.label1=tk.Label(self,text="Enter Roll Num* ",width=20)
        self.label1.place(relx=0.3,rely=0.5)
        self.rsentry=tk.Entry(self)
        self.rsentry.place(relx=0.5,rely=0.5,relwidth=0.3)
        btnupdate=Button(self,text="Select a record",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda:SelectRoll1(self))
        btnupdate.place(relx=0.2,rely=0.6,relwidth=0.3)
        btnupdate.config(cursor='mouse',bg='navy', fg='white', bd=5)
        
        record_rol=self.rsentry.get()
        
        def RecUpdate(self):
            c=len(str(self.aentry.get()))
            print(c)
            if c!=10:
                 tkinter.messagebox.showwarning("Warning", "Phone num should be of 10 Digit!!!")
            else:
                con = sq.connect('studb.db')
                c = con.cursor()
                record_rol=int(self.rsentry.get())
                dataCopy = c.execute("select count(*) from stud2;")
                values = dataCopy.fetchone()
                print (values[0])
                if record_rol >values[0]:
                    tkinter.messagebox.showerror("Error", "No Roll No. Found")

                elif self.rsentry.get() == "":
                    tkinter.messagebox.showwarning("Warning", "Please Enter a Roll num")
                else:
                    c.execute("""UPDATE stud2 SET
                             name=:nm,
                             fname=:fnm,
                             phno=:ph,
                             dob=:db,
                             gender=:gd,
                             course=:cr
                             WHERE roll=:roll""",
                             {'nm':self.nentry.get(),
                              'fnm':self.fentry.get(),
                              'ph':self.aentry.get(),
                              'db':self.ent.get(),
                              'gd':self.gent.get(),
                              'cr':self.cent.get(),
                              'roll':str(record_rol)
                             })
                    result1=tkinter.messagebox.askyesno("Update","Do you want to update this roll num ?")
                    if result1==True:
                        tkinter.messagebox.showinfo("Record Updated","Student record update successfully")
                    else:
                        return print("you press no")
                    
                    con.commit()
                    con.close()
                    print("Record updated")
        def SelectRoll1(self):
            print("Record selected")
            con = sq.connect('studb.db')
            c = con.cursor()
            record_id= int(self.rsentry.get())
            dataCopy = c.execute("select count(*) from stud2;")
            values = dataCopy.fetchone()
            print (values[0])
            if record_id >values[0]:
                 tkinter.messagebox.showerror("Error", "No roll Found")
            elif self.rsentry.get() == "":
                tkinter.messagebox.showinfo("Warning", "Please Enter a Roll num")
            else:
        
                global nentry
                global fentry
                global aentry
                global ent
                global gent
                global cent
            
            
                try:
        
                    c.execute("SELECT * FROM stud2 WHERE roll = " + str(record_id))
                    records=c.fetchall()
                except:
                    tkinter.messagebox.showinfo("Warning", "No Table found")
                    
                self.label0=tk.Label(self,text="Student Name*",width=20)
                self.label0.place(relx=0.3,rely=0.2)
                self.nentry=tk.Entry(self)
                self.nentry.place(relx=0.5,rely=0.2,relwidth=0.3)



                self.label1=tk.Label(self,text="Father's Name*",width=20)
                self.label1.place(relx=0.3,rely=0.25)
                self.fentry=tk.Entry(self)
                self.fentry.place(relx=0.5,rely=0.25,relwidth=0.3)

                self.label2=tk.Label(self,text="Phone NO.*",width=20)
                self.label2.place(relx=0.3,rely=0.3)
                self.aentry=tk.Entry(self)
                self.aentry.place(relx=0.5,rely=0.3,relwidth=0.3)

                self.label3=tk.Label(self,text="Course*",width=20)
                self.label3.place(relx=0.3,rely=0.35)
                self.cent=tk.Entry(self)
                self.cent.place(relx=0.5,rely=0.35,relwidth=0.3)
                
                self.label4=tk.Label(self,text="DOB*",width=20)
                self.label4.place(relx=0.3,rely=0.4)
                self.ent=tk.Entry(self)
                self.ent.place(relx=0.5,rely=0.4,relwidth=0.3)

                self.label5=tk.Label(self,text="Gender*",width=20)
                self.label5.place(relx=0.3,rely=0.45)
                self.gent=tk.Entry(self)
                self.gent.place(relx=0.5,rely=0.45,relwidth=0.3)

                for record in records:
                    self.nentry.insert(0,record[0])
                    self.fentry.insert(0,record[1])
                    self.aentry.insert(0,record[2])
                    self.ent.insert(0,record[6])
                    self.gent.insert(0,record[4])
                    self.cent.insert(0,record[5])



                con.commit()

            def clearData(self):
                self.nentry.delete(0,END)
                self.fentry.delete(0,END)
                self.aentry.delete(0,END)
                self.ent.delete(0,END)
                self.rsentry.delete(0,END)
                self.gent.delete(0,END)
                self.cent.delete(0,END)
            btnupdate=Button(self,text="Update Record",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda:RecUpdate(self))
            btnupdate.place(relx=0.5,rely=0.6,relwidth=0.3)
            btnupdate.config(cursor='mouse',bg='navy', fg='white', bd=5)
            btnSubmit=Button(self,text="view all record",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda:controller.show_frame(PageTwo))
            btnSubmit.place(relx=0.2,rely=0.8,relwidth=0.3)
            btnStartPage=Button(self,text="Back ",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda: controller.show_frame(StartPage) )
            btnStartPage.place(relx=0.5,rely=0.8,relwidth=0.3)
            btnclearData=Button(self,text="Clear Data ",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda:clearData(self) )
            btnclearData.place(relx=0.2,rely=0.9,relwidth=0.3)
            btnquit=Button(self, text="Log Out", command=lambda: controller.show_frame(LogIn))
            btnquit.place(relx=0.5,rely=0.9,relwidth=0.3)
            btnSubmit.config(cursor='mouse',bg='navy', fg='white', bd=5)
            btnStartPage.config(cursor='mouse',bg='navy', fg='white', bd=5)
            btnclearData.config(cursor='mouse',bg='navy', fg='white', bd=5)
            btnquit.config(cursor='mouse',bg='navy', fg='white', bd=5)
            con = sq.connect('studb.db')
            c = con.cursor()
            
class PageFive(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        tk.Frame.configure(self,bg='lawngreen')
    
        
        label0=tk.Label(self,text="Search Student Records Here",fg='grey25',bg="lawngreen",pady=4,width=50,)
        label0.place(relx=0.1,rely=0.0)
        label0.config(font=("Vineta BT",15,"bold","italic","underline"))
        self.label1=tk.Label(self,text="Enter Roll Num ",width=20)
        self.label1.place(relx=0.3,rely=0.5)
        self.rsentry=tk.Entry(self)
        self.rsentry.place(relx=0.5,rely=0.5,relwidth=0.3)
        btnshow=Button(self,text="Show record",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda:SelectRoll1(self))
        btnshow.place(relx=0.2,rely=0.7,relwidth=0.3)
        btnshow.config(cursor='mouse',bg='navy', fg='white', bd=5)
    
        def SelectRoll1(self):
            print("Record selected")
            con = sq.connect('studb.db')
            c = con.cursor()
            record_id= int(self.rsentry.get())
            dataCopy = c.execute("select count(*) from stud2;")
            values = dataCopy.fetchone()
            print (values[0])
            if record_id >values[0]:
                 tkinter.messagebox.showerror("Error", "No roll Found")
            elif self.rsentry.get() == "":
                tkinter.messagebox.showinfo("Warning", "Please Enter a Roll num")
            else:
        
                global nentry
                global fentry
                global aentry
                global ent
                global gent
                global cent
            
            
                try:
        
                    c.execute("SELECT * FROM stud2 WHERE roll = " + str(record_id))
                    records=c.fetchall()
                except:
                    tkinter.messagebox.showinfo("Warning", "No Table found")
                    
                self.label0=tk.Label(self,text="Student Name*",width=20)
                self.label0.place(relx=0.3,rely=0.2)
                self.nentry=tk.Entry(self)
                self.nentry.place(relx=0.5,rely=0.2,relwidth=0.3)



                self.label1=tk.Label(self,text="Father's Name*",width=20)
                self.label1.place(relx=0.3,rely=0.25)
                self.fentry=tk.Entry(self)
                self.fentry.place(relx=0.5,rely=0.25,relwidth=0.3)

                self.label2=tk.Label(self,text="Phone NO.*",width=20)
                self.label2.place(relx=0.3,rely=0.3)
                self.aentry=tk.Entry(self)
                self.aentry.place(relx=0.5,rely=0.3,relwidth=0.3)

                self.label3=tk.Label(self,text="Course*",width=20)
                self.label3.place(relx=0.3,rely=0.35)
                self.cent=tk.Entry(self)
                self.cent.place(relx=0.5,rely=0.35,relwidth=0.3)
                
                self.label4=tk.Label(self,text="DOB*",width=20)
                self.label4.place(relx=0.3,rely=0.4)
                self.ent=tk.Entry(self)
                self.ent.place(relx=0.5,rely=0.4,relwidth=0.3)

                self.label5=tk.Label(self,text="Gender*",width=20)
                self.label5.place(relx=0.3,rely=0.45)
                self.gent=tk.Entry(self)
                self.gent.place(relx=0.5,rely=0.45,relwidth=0.3)

                for record in records:
                    self.nentry.insert(0,record[0])
                    self.fentry.insert(0,record[1])
                    self.aentry.insert(0,record[2])
                    self.ent.insert(0,record[6])
                    self.gent.insert(0,record[4])
                    self.cent.insert(0,record[5])
                con.commit()                
                btnSubmit=Button(self,text="view all record",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda:controller.show_frame(PageTwo))
                btnSubmit.place(relx=0.2,rely=0.8,relwidth=0.3)
                btnStartPage=Button(self,text="Go to Home Page",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda: controller.show_frame(StartPage) )
                btnStartPage.place(relx=0.5,rely=0.8,relwidth=0.3)
                btnclearData=Button(self,text="Clear Data ",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda:clearData(self) )
                btnclearData.place(relx=0.2,rely=0.9,relwidth=0.3)
                btnquit=Button(self, text="Log Out", command=lambda: controller.show_frame(LogIn))
                btnquit.place(relx=0.5,rely=0.9,relwidth=0.3)
                btnSubmit.config(cursor='mouse',bg='navy', fg='white', bd=5)
                btnStartPage.config(cursor='mouse',bg='navy', fg='white', bd=5)
                btnclearData.config(cursor='mouse',bg='navy', fg='white', bd=5)
                btnquit.config(cursor='mouse',bg='navy', fg='white', bd=5)


class LogIn(tk.Frame):

    def LogInCheck(self):
        global actEntry
        global pinEntry

        act = "j"
        pin = "py"

        actNum = actEntry.get()
        pinNum = pinEntry.get()

        print("FUNCTION RUN")
        if actNum == act and pinNum == pin:
            print("CORRECT")
            actEntry.delete(0,END)
            pinEntry.delete(0,END)
            self.controller.show_frame(StartPage)
        elif actNum != act or pinNum != pin: 
            print("INCORRECT")
            tkinter.messagebox.showerror("Error","Incorrect Login Input")
            
            self.controller.show_frame(LogIn)

    def __init__(self, parent, controller):

        global actEntry
        global pinEntry
        self.controller = controller

        tk.Frame.__init__(self, parent)

        tk.Frame.configure(self,bg='lawngreen')
        label=tk.Label(self,text=" ",bd=12,width=70,height=35,bg="lawngreen",fg="blue",font=("times",12,"bold","italic")).pack()
        def time(): 
            string = strftime('%I:%M:%S %p') 
            lbl.config(text = string) 
            lbl.after(1000, time)  
        lbl = Label(self, font = ('calibri', 60, 'bold'),background = 'lawngreen',foreground = 'grey8',relief=RIDGE)  
        lbl.place(relx=0.01,rely=0.0) 
        time() 
        label0=tk.Label(self,text="Admin Login Here",fg='grey8',bg="lawngreen",pady=4,width=50)
        label0.place(relx=-0.25,rely=0.2)
        label0.config(font=("Vineta BT",15,"bold","italic","underline"))
        labelinfo=tk.Label(self,text="NOTE:Ask Admin For ID & Password",fg='red',bg="lawngreen",pady=4,width=50,)
        labelinfo.place(relx=0.05,rely=0.27)
        labelinfo.config(font=("Times New Roman",9,"bold","italic"))
        btnStartPage=Button(self,text="Student Login Here ",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda:controller.show_frame(stlogin) )
        btnStartPage.place(relx=0.0,rely=0.7,relwidth=0.3)
        btnStartPage.config(cursor='mouse',bg='navy', fg='white', bd=5)
        actLabel = Label(self, text = 'Username:',relief=RIDGE)
        actLabel.place(relx=0.05,rely=0.3)
        actEntry = Entry(self,relief=SOLID)
        actEntry.place(relx=0.1,rely=0.3)
        pinLabel = Label(self, text = 'Password:',relief=RIDGE)
        pinLabel.place(relx=0.05,rely=0.35)
        pinEntry = Entry(self, show ="*",relief=SOLID)
        pinEntry.place(relx=0.1,rely=0.35)      
        def imgview1(self):
            self.img  = Image.open('userlogin.png')
            self.img2 =  Image.open('63940.png')
            self.img3=  Image.open('ppt3.png')
            self.img = self.img.resize((50,20)) 
            self.img2= self.img2.resize((50,20))
            self.img3 = self.img3.resize((910,700))
            photo=ImageTk.PhotoImage(self.img)
            photo1=ImageTk.PhotoImage(self.img2)
            photo3=ImageTk.PhotoImage(self.img3)
            self.lab=Button(self,image=photo,command=self.LogInCheck) 
            self.lab1=Button(self,image=photo1,command = controller.destroy) 
            self.lab2=Label(self,image=photo3,relief=SUNKEN)
            self.img.image=photo
            self.img2.image=photo1
            self.img3.image=photo3
            self.lab.place(relx=0.05,rely=0.4)
            self.lab1.place(relx=0.12,rely=0.4)
            self.lab2.place(relx=0.33,rely=0.0)
            self.lab1.config(cursor='mouse',bg='red', fg='white', bd=15)
            self.lab.config(cursor='mouse',bg='black', fg='white', bd=15)
        return imgview1(self)
    
class stlogin(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        tk.Frame.configure(self,bg='lawngreen')
        label0=tk.Label(self,text="Student Login Here",fg='grey25',bg="lawngreen",pady=4,width=50,)
        label0.place(relx=0.1,rely=0.0)
        label0.config(font=("Vineta BT",15,"bold","italic","underline"))
        con = sq.connect('studb.db')
        c = con.cursor()

        c.execute('CREATE TABLE IF NOT EXISTS user (username TEXT NOT NULL UNIQUE ,password TEX NOT NULL UNIQUE);')
        con.commit()
        con.close()
        # Some Usefull variables
        self.username = StringVar()
        self.password = StringVar()
        self.n_username = StringVar()
        self.n_password = StringVar()
        #Create Widgets
        self.widgets()
    #Login Function
    def login(self):
    	#Establish Connection
        con = sq.connect('studb.db')
        c = con.cursor()

        #Find user If there is any take proper action
        find_user = ('SELECT * FROM user WHERE username = ? and password = ?')
        c.execute(find_user,[(self.username.get()),(self.password.get())])
        result = c.fetchall()
        
        if result:
            
            self.logf.pack_forget()
            self.head['text'] = self.username.get() + '\n Loged In'
            self.head['pady'] = 150
            print('hello')
            
   
        else:
            tkinter.messagebox.showerror('Oops!','Username Not Found.')
            
    def new_user(self):
    	#Establish Connection
        
        con = sq.connect('studb.db')
        c = con.cursor()
        find_user = ('SELECT * FROM user WHERE username = ?')
        c.execute(find_user,[(self.username.get())])        
        try:
            insert = 'INSERT INTO user(username,password) VALUES(?,?)'
            c.execute(insert,[(self.n_username.get()),(self.n_password.get())])
            tkinter.messagebox.showinfo('Success!','Account Created!')
            self.log()
        except:
            tkinter.messagebox.showinfo('Already present','Username Taken Try a Diffrent One.')
            self.cr()

        con.commit()

        #Frame Packing Methords
    def log(self):
        self.username.set('')
        self.password.set('')
        self.crf.pack_forget()
        self.head['text'] = 'LOGIN'
        self.logf.pack()
    def cr(self):
        self.n_username.set('')
        self.n_password.set('')
        self.logf.pack_forget()
        self.head['text'] = 'Create Account'
        self.crf.pack()
        
    #Draw Widgets
    def widgets(self):
        self.head = Label(self,text = 'LOGIN',bg='lawngreen',font = ('',35),pady = 10)
        self.head.place(relx=0.3,rely=0.3)
        self.logf = Frame(self,bg="lawngreen",padx =10,pady = 10)
        Label(self.logf,text = 'Username: ',font = ('',20),pady=5,padx=5).grid(sticky = W)
        Entry(self.logf,textvariable = self.username,bd = 5,font = ('',15)).grid(row=0,column=1)
        Label(self.logf,text = 'Password: ',font = ('',20),pady=5,padx=5).grid(sticky = W)
        Entry(self.logf,textvariable = self.password,bd = 5,font = ('',15),show = '*').grid(row=1,column=1)
        Button(self.logf,text = ' Login ',bd = 3 ,font = ('',15),padx=5,pady=5,command=self.login).grid()
        Button(self.logf,text = ' Create Account ',bd = 3 ,font = ('',15),padx=5,pady=5,command=self.cr).grid(row=2,column=1)
        self.logf.place(relx=0.3,rely=0.5)
        
        self.crf = Frame(self,padx =10,pady = 10)
        Label(self.crf,text = 'Username: ',font = ('',20),pady=5,padx=5).grid(sticky = W)
        Entry(self.crf,textvariable = self.n_username,bd = 5,font = ('',15)).grid(row=0,column=1)
        Label(self.crf,text = 'Password: ',font = ('',20),pady=5,padx=5).grid(sticky = W)
        Entry(self.crf,textvariable = self.n_password,bd = 5,font = ('',15),show = '*').grid(row=1,column=1)
        Button(self.crf,text = 'Create Account',bd = 3 ,font = ('',15),padx=5,pady=5,command=self.new_user).grid()
        Button(self.crf,text = 'Go to Login',bd = 3 ,font = ('',15),padx=5,pady=5,command=self.log).grid(row=2,column=1)
        self.crf.place(relx=0.3,rely=0.5)
if __name__ == "__main__":
     
    app = Master()
    app.mainloop()
    
#===========Questions==============
#add roll 10 data then it is not checking the rest roll data
#entry type validation in entries
#event handling
In [ ]:
import jovian
jovian.commit()
[jovian] Saving notebook..
In [ ]:
num