Sunday, September 13, 2020

Python GUI Project Very Simple ,Python +Sqlite +Tkinter

GUI Based Project Python +SQLite+Tkinter
In [ ]:
from tkinter import *

from tkinter import messagebox
def createtable():
      import sqlite3
      msg="TABLE CREATED SUCCESSFULLY"
      try:
         mdb = sqlite3.connect('CS.db')
         myc = mdb.cursor()
         myc.execute('create table student5(name char(40),rollno int)')
         mdb.close()
      except:
         msg="FILE CREATED ALREADY"
      t=Tk()
      t.geometry("200x200")
      label = Label( t, text=msg, relief=RAISED )
      label.pack()
      t.mainloop()
      
      
def insert():
      t=Tk()
      t.geometry("200x200")
      k=Entry(t)
      l=Entry(t)
      def insql():
            m=k.get()
            n=l.get()
            print(m,n)
            import sqlite3
            mdb = sqlite3.connect('CS.db')
            myc = mdb.cursor()
            myc.execute("INSERT INTO student5 VALUES ('"+m+"','"+n+"')")
            mdb.commit()
            mdb.close()
       
      k.place(x=10,y=10)
      l.place(x=10,y=40)
      k.pack()
      l.pack()
      b=Button(t,text="Submit",command=insql)
      b.pack()
      msg="ROW INSERTED SUCESSFULLY"
      label = Label( t, text=msg, relief=RAISED )
      t.mainloop()
      
     
def show():
      
       t=Tk()
       t.geometry("200x200")
       import sqlite3
       mdb = sqlite3.connect('CS.db')
       myc = mdb.cursor()
       myc.execute('select * from student5')
       record=myc.fetchall()
       label = Label( t, text="CS STUDENT RECORD MANAGEMENT ",relief=RAISED )
       label.pack()
       
       for x in record:
           msg= "NAME:   "+str(x[0])+"     ROLLNO   "+str(x[1])
           label = Label( t, text=msg, relief=RAISED )
           label.pack()
       mdb.close()
       t.mainloop()
def quit():
      msg= messagebox.showinfo("quit Program")
      sys.exit()
top = Tk()
top.geometry("400x600")
l=Label(top,text="Computer Science Student Record Management ")
l.pack()
B1 = Button(top, text = "CREATE TABLE",bg='red', command = createtable)
B1.place(x = 10,y = 100)

B2 = Button(top, text = "INSERT ROW ",bg='yellow', command = insert)
B2.place(x = 10,y = 130)

B3 = Button(top, text = "SHOW TABLE ",bg='green', command = show)
B3.place(x = 10,y = 160)

B4 = Button(top, text = "QUIT PROGRAM",bg='blue', command = quit)
B4.place(x = 10,y = 190)
top.mainloop()