0% found this document useful (0 votes)
9 views

Library Tkinter - Py

,

Uploaded by

4fxstrange
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Library Tkinter - Py

,

Uploaded by

4fxstrange
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

import mysql.

connector as m
from tkinter import *
def crdata():
import mysql.connector as m
con=m.connect(host="localhost",user="root",passwd="samar")
cur=con.cursor()
cmd="create database if not exist myproject"
cur.execute(cmd)
con.close()

def crtable():
import mysql.connector as m
con=m.connect(host="localhost", user="root", passwd="samar",
database="myproject")
cur=con.cursor()
cmd="create table if not exists book(bno int,bnm varchar(25),ath
varchar(20),sub varchar(25),aty int, prc float)"
cur.execute(cmd)
co.close()
def addbook():
global dm
def save():
con=m.connect(host="localhost", user="root", passwd="samar",
database="myproject")
cur=con.cursor()
cmd="insert into book values({},'{}','{}','{}',{},
{})".format(int(t1.get()),t2.get(),t3.get(),t4.get(),int(t5.get()),float(t6.get()))
cur.execute(cmd)
con.commit()
con.close()
dm.destroy()

dm=Tk()
dm.title("Add Book Screen")
dm.gepmetry("650x650")
l1=Label(dm,text="Add Book",font=("calibri",25))
l2=Label(dm,text="Enter Book No.",font=("calibri",25))
l3=Label(dm,text="Enter Book Name",font=("calibri",25))
l4=Label(dm,text="Enter Author's Name",font=("calibri",25))
l5=Label(dm,text="Enter Subject",font=("calibri",25))
l6=Label(dm,text="Enter quantity",font=("calibri",25))
l7=Label(dm,text="Enter Price",font=("calibri",25))
t1=Entry(dm,width=15,font=("calibri",25))
t2=Entry(dm,width=15,font=("calibri",25))
t3=Entry(dm,width=15,font=("calibri",25))
t4=Entry(dm,width=15,font=("calibri",25))
t5=Entry(dm,width=15,font=("calibri",25))
t6=Entry(dm,width=15,font=("calibri",25))
t7=Entry(dm,width=15,font=("calibri",25))
b1=Button(dm,text="ADD",font=("calibri",25),command=save)
t1.focus()
l1.place(x=190,y=10)
l2.place(x=190,y=80)
l3.place(x=190,y=120)
l4.place(x=190,y=160)
l5.place(x=190,y=200)
l6.place(x=190,y=240)
l7.place(x=190,y=290)
t1.place(x=300,y=80)
t2.place(x=300,y=120)
t3.place(x=300,y=160)
t4.place(x=300,y=200)
t5.place(x=300,y=240)
t6.place(x=300,y=290)
b1.place(x=60,y=350)

def modbook():
global dm
def update():
con=m.connect(host="localhost", user="root", passwd="samar",
database="myproject")
cur=con.cursor()
cmd="update book set bnm='{}',ath='{}',sub='{}',aty={},prc={}
where=bno={}".format(t2.get(),t3.get(),t4.get(),int(t5.get()),float(t6.get()),int(t
1.get()))
cur.execute(cmd)
con.commit()
con.close()
dm.destroy()

dm=Tk()
dm.title("Modify Book Screen")
dm.geometry('1000x600')
l1=Label(dm,text="MODIFY BOOK",font=("Cooper",30))
l2=Label(dm,text="Enter Book number to Modify",font=("Engravers MT",20))
l3=Label(dm,text="Enter New Book Name",font=("Cooper",20))
l4=Label(dm,text="Enter New Author Name",font=("Cooper",20))
l5=Label(dm,text="Enter New Subject",font=("Cooper",20))
l6=Label(dm,text="Enter New Quantity",font=("Cooper",20))
l7=Label(dm,text="Enter New Price",font=("Cooper",20))
t1=Entry(dm,width=15,font=("Engravers MT",20))
t2=Entry(dm,width=15,font=("Cooper",20))
t3=Entry(dm,width=15,font=("Cooper",20))
t4=Entry(dm,width=15,font=("Cooper",20))
t5=Entry(dm,width=15,font=("Cooper",20))
t6=Entry(dm,width=15,font=("Cooper",20))
b1=Button(dm,text="MODIFY",font=("Cooper",20),command=update)
t1.focus()
l1.place(x=180,y=10)
l2.place(x=10,y=80)
l3.place(x=10,y=120)
l4.place(x=10,y=160)
l5.place(x=10,y=200)
l6.place(x=10,y=240)
l7.place(x=10,y=290)
t1.place(x=700,y=80)
t2.place(x=400,y=120)
t3.place(x=400,y=160)
t4.place(x=400,y=200)
t5.place(x=400,y=240)
t6.place(x=400,y=290)
b1.place(x=60,y=350)

def delbook():
global dm
def dele():
con=m.connect(host="localhost",user="root",passwd="samar",database="myproject")
cur=con.cursor()
cmd="delete from book where bno={}".format(int(t1.get()))
cur.execute(cmd)
con.commit()
con.close()
dm.destroy()

dm=Tk()
dm.title("Delete Book Screen")
dm.geometry("1000x300")
l1=Label(dm,text="DELETE BOOK",font=("Cooper",30))
l2=Label(dm,text="Enter Book number to Delete",font=("Engravers MT",20))
t1=Entry(dm,width=15,font=("Engravers MT",20))
b1=Button(dm,text="DELETE",font=("Cooper",20),command=dele)
t1.focus()
l1.place(x=180,y=10)
l2.place(x=10,y=80)
t1.place(x=700,y=80)
b1.place(x=60,y=150)
def back():
dm.destroy()
def issbook():
global dm
def issue():

con=m.connect(host="localhost",user="root",passwd="samar",database="myproject")
cur=con.cursor()
cmd="update book set qty=qty - {} where bno={} and
qty>{}".format(int(t2.get()),int(t1.get()),int(t2.get()))
cur.execute(cmd)
if cur.rowcount==1:
l4=Label(dm,text="Book Issued",font=("Engravers MT",20))
else:
l4=Label(dm,text="Book Not Found or Less Quantity",font=("Engravers
MT",20))
l4.place(x=60,y=240)
b1=Button(dm,text="Back",font=("Cooper",20),command=back)
b1.place(x=60,y=300)
con.commit()
con.close()

dm=Tk()
dm.title("Issue Book Screen")
dm.geometry("1000x400")
l1=Label(dm,text="ISSUE BOOK",font=("Cooper",30))
l2=Label(dm,text="Enter Book number to Issue",font=("Engravers MT",20))
l3=Label(dm,text="Enter Quantity to Issue",font=("Engravers MT",20))
t1=Entry(dm,width=15,font=("Engravers MT",20))
t2=Entry(dm,width=15,font=("Engravers MT",20))
b1=Button(dm,text="Issue Book",font=("Cooper",20),command=issue)
t1.focus()
l1.place(x=180,y=10)
l2.place(x=10,y=80)
t1.place(x=700,y=80)
l3.place(x=10,y=120)
t2.place(x=700,y=120)
b1.place(x=60,y=180)
def retbook():
global dm
def retu():

con=m.connect(host="localhost",user="root",passwd="samar",database="myproject")
cur=con.cursor()
cmd="update book set qty=qty + {} where
bno={}".format(int(t2.get()),int(t1.get()))
cur.execute(cmd)
if cur.rowcount==1:
l4=Label(dm,text="Book Returned",font=("Engravers MT",20))
else:
l4=Label(dm,text="Book Not Found",font=("Engravers MT",20))
l4.place(x=60,y=240)
b1=Button(dm,text="Back",font=("Cooper",20),command=back)
b1.place(x=60,y=300)
con.commit()
con.close()

dm=Tk()
dm.title("Return Book Screen")
dm.geometry("1000x400")
l1=Label(dm,text="RETURN BOOK",font=("Cooper",30))
l2=Label(dm,text="Enter Book number to Return",font=("Engravers MT",20))
l3=Label(dm,text="Enter Quantity to Return",font=("Engravers MT",20))
t1=Entry(dm,width=15,font=("Engravers MT",20))
t2=Entry(dm,width=15,font=("Engravers MT",20))
b1=Button(dm,text="Return Book",font=("Cooper",20),command=retu)
t1.focus()
l1.place(x=180,y=10)
l2.place(x=10,y=80)
t1.place(x=700,y=80)
l3.place(x=10,y=120)
t2.place(x=700,y=120)
b1.place(x=60,y=180)
def choice():
global t
m=int(t.get())
if m==1:
addbook()
elif m==2:
modbook()
elif m==3:
delbook()
elif m==4:
issbook()
elif m==5:
retbook()
elif m==6:
mf.destroy()
def mainscr():
global mf,t
mf=Tk()
mf.title("Main Menu Screen")
mf.geometry("600x600")
l1=Label(mf,text="Library Project",font=("Cooper",30))
l2=Label(mf,text="1. Add a New Book",font=("Cooper",20))
l3=Label(mf,text="2. Modify a Book",font=("Cooper",20))
l4=Label(mf,text="3. Delete a Book",font=("Cooper",20))
l5=Label(mf,text="4. Issue a Book",font=("Cooper",20))
l6=Label(mf,text="5. Return a Book",font=("Cooper",20))
l7=Label(mf,text="6. Exit",font=("Cooper",20))
l8=Label(mf,text="Choose from 1 to 6 ",font=("Cooper",20))
t=Entry(mf,width=5,font=("Cooper",20))
t.focus()
b=Button(mf,text="Submit",font=("Cooper",25),command=choice)
l1.place(x=60,y=10)
l2.place(x=10,y=80)
l3.place(x=10,y=120)
l4.place(x=10,y=160)
l5.place(x=10,y=200)
l6.place(x=10,y=240)
l7.place(x=10,y=290)
l8.place(x=10,y=330)
t.place(x=300,y=330)
b.place(x=60,y=400)
mf.mainloop()
crdata()
crtable()
mf=None
dm=None
x=None
t=None
mainscr()

You might also like