Jovian
⭐️
Sign In
In [4]:
import tkinter as tk                
from tkinter import font  as tkfont 
from tkinter import ttk
import sqlite3 as sq
import tkinter.messagebox
from PIL import Image,ImageTk
import ctypes

class SampleApp(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 (login,StartPage,add1,view,delete,search,update):
            frame=F(container,self)
            self.frames[F] = frame

           
            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame(login)
        self.state("zoomed")
    def show_frame(self, container):
        '''Show a frame for the given page name'''
        frame = self.frames[container]
        frame.tkraise()

class login(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        tk.Frame.configure(self,bg="purple")
        self.controller = controller
        label = tk.Label(self, text="Student database system",bg='black',fg='yellow')
        label.config(font=("Courier", 44))
        label.pack(side="top", fill="x", pady=10)
        
        USERID=tk.StringVar(self,'') 
        PASSWORD=tk.StringVar(self,'') 
        a="farin"
        b="786"
        
        button1 = tk.Button(self, text="login",width=50,bg='black',fg='yellow',
                            command=lambda:login1(self))
        button1.place(relx=0.15,rely=0.6)
        
        label1 = tk.Label(self, text="USERID",width=30,bg="black",fg="yellow")
        label1.place(relx=0.05,rely=0.3)                    
        
        entry1=tk.Entry(self,width=55,textvariable=USERID)
        entry1.place(relx=0.23,rely=0.3)
        
        label2 = tk.Label(self, text="PASSWORD",width=30,bg="black",fg="yellow")
        label2.place(relx=0.05,rely=0.4)                    
        
        entry2=tk.Entry(self,width=55,show="*",textvariable=PASSWORD)
        entry2.place(relx=0.23,rely=0.4)
        
        
        def login1(self):
            
            if str(USERID.get())=="":
                tkinter.messagebox.showinfo("ERROR","user blank")
            elif PASSWORD.get()=="":
                tkinter.messagebox.showinfo("ERROR","pass blank")
  
            elif str(USERID.get())==a and PASSWORD.get()==b:

                self.controller.show_frame(StartPage)

            else:
                tkinter.messagebox.showinfo("ERROR","wrong input")

        def img1(self):
                self.img=Image.open("slide1.jpg")
                self.img=self.img.resize((700,640))
                photo=ImageTk.PhotoImage(self.img)
                self.lab=tk.Label(self,image=photo)
                self.img.image=photo
                self.lab.place(relx=0.5,rely=0.12)
        return img1(self)
    
        
        
        
class StartPage(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        tk.Frame.configure(self,bg="purple")
        self.controller = controller
        label = tk.Label(self, text="Student database system",bg='black',fg='yellow')
        label.config(font=("Courier", 44))
        label.pack(side="top", fill="x", pady=10)

        button1 = tk.Button(self, text="add",width=50,bg='black',fg='yellow',
                            command=lambda: controller.show_frame(add1))
        
        button2 = tk.Button(self, text="view",width=50,bg='black',fg='yellow',
                            command=lambda: controller.show_frame(view))
    
        button3 = tk.Button(self, text="delete",width=50,bg='black',fg='yellow',
                            command=lambda: controller.show_frame(delete))
       
        button4 = tk.Button(self, text="search",width=50,bg='black',fg='yellow',
                            command=lambda: controller.show_frame(search))
        button5 = tk.Button(self, text="update",width=50,bg='black',fg='yellow',
                            command=lambda: controller.show_frame(update))
        
   
        button1.place(relx=0.7,rely=0.3)
        button2.place(relx=0.7,rely=0.4)
        button3.place(relx=0.7,rely=0.5)
        button4.place(relx=0.7,rely=0.6)
        button5.place(relx=0.7,rely=0.7)
        def img1(self):
                self.img=Image.open("trident .jpg")
                self.img=self.img.resize((850,600))
                photo=ImageTk.PhotoImage(self.img)
                self.lab=tk.Label(self,image=photo)
                self.img.image=photo
                self.lab.place(relx=0.01,rely=0.12)
        return img1(self)
    
class add1(tk.Frame):
   
    
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller
        tk.Frame.configure(self,bg="purple")
    
        
        e1=tk.StringVar(self,'') 
        e2=tk.StringVar(self,'') 
        e3=tk.StringVar(self,'') 
        e4=tk.StringVar(self,'') 
        
        
        label1 =tk.Label(self, text="name",width=10,bg="black",fg="yellow")
        label1.place(relx=0.1,rely=0.2)                
       
        entry1=tk.Entry(self,width=30,textvariable=e1)
        entry1.place(relx=0.3,rely=0.2)
        
        label2 = tk.Label(self, text="roll",width=10,bg="black",fg="yellow")
        label2.place(relx=0.1,rely=0.3)                    
        
        entry2=tk.Entry(self,width=30,textvariable=e2)
        entry2.place(relx=0.3,rely=0.3)
        
        label3 = tk.Label(self, text="address",width=10,bg="black",fg="yellow")
        label3.place(relx=0.1,rely=0.4)                   
        
        entry3=tk.Entry(self,width=30,textvariable=e3)
        entry3.place(relx=0.3,rely=0.4)
        
        label4 = tk.Label(self, text="phnno",width=10,bg="black",fg="yellow")
        label4.place(relx=0.1,rely=0.5)                   
        
        entry4=tk.Entry(self,width=30,textvariable=e4)
        entry4.place(relx=0.3,rely=0.5)
        
        button = tk.Button(self, text="submit",width=30,bg="black",fg="yellow",font=("bold"),
                           command=lambda:(create(self)))
        button.place(relx=0.3,rely=0.6)
        
        
        button = tk.Button(self, text="Go to the start page",width=30,bg="black",fg="yellow",font=("bold"),
                           command=lambda: controller.show_frame(StartPage))
        button.place(relx=0.3,rely=0.7)
        
    
        def create(self):
           
            
            con=sq.connect("data.db")
            c=con.cursor()
            f=e2.get()
            try:
                f1=int(f)
            except ValueError:
                tkinter.messagebox.showerror("warning","invalid ROLLNO")
        
            v=int(len(str(e4.get())))
            if  e1.get()=="":
                tkinter.messagebox.showwarning("warning","name is empty")
            elif e2.get()=="":
                tkinter.messagebox.showwarning("warning","roll is empty")
            elif e3.get()=="":
                tkinter.messagebox.showwarning("warning","address is empty")        
            elif e4.get()=="":
                tkinter.messagebox.showwarning("warning","phnno is empty")
            elif v!=10:  
                tkinter.messagebox.showwarning("warning","no. shoud be 10")    
            else:
                try:
                
                    c.execute('CREATE TABLE IF NOT EXISTS table4(name TEXT UNIQUE,roll INTEGER UNIQUE,address TEXT,phnno INTEGER UNIQUE)')
                    c.execute('INSERT INTO table4(name,roll,address,phnno) VALUES(?,?,?,?)',[e1.get(),e2.get(),e3.get(),e4.get()])
                    result=tkinter.messagebox.askyesno("submit","do you want to submit?")
                    if result==True:
                        tkinter.messagebox.showinfo("record submitted","your record submitted succssessfully")
                    else:
                        return print('no')  
                except:
                     tkinter.messagebox.showwarning("Warning","Record already present")
                con.commit() 
                
                
                
                

class view(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller
        tk.Frame.configure(self,bg="purple")
        
        def tree1(self):
            
            con = sq.connect('data.db')
            c = con.cursor()
            c.execute("SELECT * FROM table4")
            
            self.tree=ttk.Treeview(self)
            self.tree["columns"]=("e1","e2","e3","e4","e5")
            self.tree.column("#0", width=50, stretch=tk.NO)
            self.tree.column("e1", width=120, stretch=tk.NO)
            self.tree.column("e2", width=120,stretch=tk.NO)
            self.tree.column("e3", width=60, stretch=tk.NO)
            self.tree.column("e4", width=60, 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="roll",anchor=tk.W)
            self.tree.heading("e3", text="address",anchor=tk.W)
            self.tree.heading("e4", text="phnno",anchor=tk.W)
        
          
            self.tree.place(relx=0.2,rely=0.1,width=800,height=400)
           
             #self.tree.tag_configure("evenrow",background='white',foreground='black')
             #self.tree.tag_configure("oddrow",background='black',foreground='white')

       
            index=id=1
            for row in c:
                self.tree.insert("", index=id, text=id, values=row)
                index=id=index+1
            con.commit()

        btnViewRec=tk.Button(self,text="View All Records",bg="ghost white",font=("bold"),command=lambda:tree1(self) )
        btnViewRec.place(relx=0.3,rely=0.7,relwidth=0.4)
        btnViewRec.config(bg='black', fg='yellow')
        button = tk.Button(self, text="Go to the add page",width=20,bg="black",fg="yellow",font=("bold"),
                           command=lambda: controller.show_frame(add1))
        button.place(relx=0.8,rely=0.2)
                
        button = tk.Button(self, text="Go to the delete page",width=20,bg="black",fg="yellow",font=("bold"),
                           command=lambda: controller.show_frame(delete))
        button.place(relx=0.8,rely=0.3)
                
        button = tk.Button(self, text="Go to the search page",width=20,bg="black",fg="yellow",font=("bold"),
                           command=lambda: controller.show_frame(search))
        button.place(relx=0.8,rely=0.4)
                
        button = tk.Button(self, text="Go to the update page",width=20,bg="black",fg="yellow",font=("bold"),
                           command=lambda: controller.show_frame(update))
        button.place(relx=0.8,rely=0.5)
                

class delete(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        tk.Frame.configure(self,bg="purple")
        
        label6 = tk.Label(self, text="roll",width=10,bg="black",fg="yellow")
        label6.place(relx=0.1,rely=0.3)                    
        
        entry6=tk.Entry(self,width=30)
        entry6.place(relx=0.3,rely=0.3)

        button = tk.Button(self, text="delete",width=30,bg="black",fg="yellow",font=("bold"),
                           command=lambda:(delete1(self)))
        button.place(relx=0.3,rely=0.6)
        button = tk.Button(self, text="Go to the start page",width=30,bg="black",fg="yellow",font=("bold"),
                           command=lambda: controller.show_frame(StartPage))
        button.place(relx=0.3,rely=0.7)
        
        def delete1(self):
            
            con = sq.connect('data.db')           
            c = con.cursor()
            
            c.execute("DELETE FROM table4 WHERE roll= "+entry6.get())
            result=tkinter.messagebox.askyesno("delete","do you want to delete?")
            
            if result==True:
                tkinter.messagebox.showinfo("record deleted","your record deleted succssessfully")
            else:
                return print('no')

            
            
            con.commit()

class search(tk.Frame):
     def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        tk.Frame.configure(self,bg="purple")
        global entry1
        global entry2
        global entry3
        global entry4
        
        button = tk.Button(self, text="Go to the start page",width=30,bg="black",fg="yellow",font=("bold"),
                           command=lambda: controller.show_frame(StartPage))
        button.place(relx=0.3,rely=0.6)
        
        
        label1 =tk.Label(self, text="name",width=10,bg="black",fg="yellow")
        label1.place(relx=0.1,rely=0.2)                
       
        self.entry1=tk.Entry(self,width=30)
        self.entry1.place(relx=0.3,rely=0.2)
        
        label2 = tk.Label(self, text="roll",width=10,bg="black",fg="yellow")
        label2.place(relx=0.1,rely=0.3)                    
        
        entry2=tk.Entry(self,width=30)
        entry2.place(relx=0.3,rely=0.3)
        
        label3 = tk.Label(self, text="address",width=10,bg="black",fg="yellow")
        label3.place(relx=0.1,rely=0.4)                   
        
        entry3=tk.Entry(self,width=30)
        entry3.place(relx=0.3,rely=0.4)
        
        label4 = tk.Label(self, text="phnno",width=10,bg="black",fg="yellow")
        label4.place(relx=0.1,rely=0.5)                   
        
        entry4=tk.Entry(self,width=30)
        entry4.place(relx=0.3,rely=0.5)
        
       
        button = tk.Button(self, text="search",width=10,bg="black",fg="yellow",font=("bold"),
                           command=lambda:(search1(self)))
        button.place(relx=0.1,rely=0.7)
        
        entry5=tk.Entry(self,width=30)
        entry5.place(relx=0.3,rely=0.7)
        
        def search1(self):
            var=str(entry5.get())
            con = sq.connect('data.db')           
            c = con.cursor()
            try:
                ser=int(entry5.get())
            except ValueError:
                tkinter.messagebox.showerror("ERROR","user blank/wrong input")
                
            d=c.execute("select count (*) from table4")
            f=d.fetchone()
            if ser>f[0]:
                tkinter.messagebox.showinfo("error","roll not found")
            
            else:
                c.execute("SELECT * FROM table4 WHERE roll= "+str(ser))
                a=c.fetchall()

            for record in a:
                self.entry1.insert(0,record[0])
                entry2.insert(0,record[1])
                entry3.insert(0,record[2])
                entry4.insert(0,record[3])
            

            con.commit()
            con.close()
class update(tk.Frame): 
     def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        tk.Frame.configure(self,bg="purple")
         
        button = tk.Button(self, text="Go to the start page",width=30,bg="black",fg="yellow",font=("bold"),
                           command=lambda: controller.show_frame(StartPage))
        button.place(relx=0.3,rely=0.6)
        entry5=tk.Entry(self,width=30)
        entry5.place(relx=0.3,rely=0.7)
        
        def update1(self):       
            con = sq.connect('data.db')           
            c = con.cursor()
            serv=int(entry5.get())
            c.execute("""update table4 SET
                    name=:a1,
                    address=:a2,
                    phnno=:a3
                    WHERE roll=:a4""",
                      {
                        'a1':entry1.get(),
                        'a2':entry2.get(),
                        'a3':entry3.get(),
                        'a4':str(serv)    
                          
                      })
            result=tkinter.messagebox.askyesno("update","do you want to update?")
            if result==True:
                tkinter.messagebox.showinfo("record update","your record updated succssessfully")
            else:
                return print('no')

            
            con.commit()
            con.close()
        
        def search1(self): 
            con = sq.connect('data.db')           
            c = con.cursor()
            ser=int(entry5.get())
            c.execute("SELECT * FROM table4 WHERE roll= "+str(ser))
            a=c.fetchall()
            
            con.commit()
            
            
            global entry1
            global entry2
            global entry3
            global entry4
         
            label1 =tk.Label(self, text="name",width=10,bg="black",fg="yellow")
            label1.place(relx=0.1,rely=0.2)                

            entry1=tk.Entry(self,width=30)
            entry1.place(relx=0.3,rely=0.2)

            label2 = tk.Label(self, text="roll",width=10,bg="black",fg="yellow")
            label2.place(relx=0.1,rely=0.3)                    

            entry2=tk.Entry(self,width=30)
            entry2.place(relx=0.3,rely=0.3)

            label3 = tk.Label(self, text="address",width=10,bg="black",fg="yellow")
            label3.place(relx=0.1,rely=0.4)                   

            entry3=tk.Entry(self,width=30)
            entry3.place(relx=0.3,rely=0.4)

            label4 = tk.Label(self, text="phnno",width=10,bg="black",fg="yellow")
            label4.place(relx=0.1,rely=0.5)                   

            entry4=tk.Entry(self,width=30)
            entry4.place(relx=0.3,rely=0.5)

            
            for record in a:
                entry1.insert(0,record[0])
                entry2.insert(0,record[1])
                entry3.insert(0,record[2])
                entry4.insert(0,record[3])
        buttonsr = tk.Button(self, text="search",width=10,bg="black",fg="yellow",font=("bold"),
                               command=lambda:(search1(self)))
        buttonsr.place(relx=0.1,rely=0.7)
        
        buttonup=tk.Button(self, text="update",width=10,bg="black",fg="yellow",font=("bold"),
                               command=lambda:(update1(self)))
        buttonup.place(relx=0.1,rely=0.8)
        entry5=tk.Entry(self,width=30)
        entry5.place(relx=0.2,rely=0.7)

            
app = SampleApp()
app.mainloop()
In [8]:
import jovian
In [ ]:
jovian.commit()
[jovian] Saving notebook..
In [ ]:

import tkinter as tkinter
import sqlite3 as sq
con=sq.connect("data.db")
c=con.cursor()
# c.execute('CREATE TABLE IF NOT EXISTS table3(id INTEGER ,name TEXT UNIQUE,roll INTEGER UNIQUE,address TEXT,phnno INTEGER UNIQUE)')
c.execute('SELECT * FROM table3 WHERE roll=2')
   
con.commit()    

In [ ]:
import jovian

In [ ]:
jovian.commit()
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
from tkinter import *

def main_account_screen():
    global main_screen
    main_screen.geometry("1920x1080") 
    main_screen.title("Account Login")  
main_screen = Tk() 




Button(text="Login", height="2", width="30").pack()
Label(text="").pack()

main_screen.mainloop()  # start the GUI

main_account_screen()  # call the main_account_screen() function
In [ ]: