-
Notifications
You must be signed in to change notification settings - Fork 4
/
srchBk.py
78 lines (50 loc) · 2.52 KB
/
srchBk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from tkinter import *
from PIL import ImageTk,Image
from tkinter import messagebox
import pymysql
# root password and database
mypass = "samy"
mydatabase="library2"
con = pymysql.connect(host="localhost",user="root",password=mypass,database=mydatabase)
cur = con.cursor()
bookTable = "books" #Book Table
def search():
global bookInfo1,Canvas1,con,cur,bookTable,root
root = Tk()
root.title("Searching Book")
root.minsize(width=800,height=900)
root.maxsize(width=800,height=900)
Canvas1 = Canvas(root)
Canvas1.config(bg="#373a40")
Canvas1.pack(expand=True,fill=BOTH)
headingFrame1 = Frame(root,bd=0)
headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheight=0.13)
headingLabel = Label(headingFrame1, text="Searching Books", bg='#ff414d', fg='black', font=('Consolas',18))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)
labelFrame = Frame(root,bg='#222831')
labelFrame.place(relx=0.1,rely=0.35,relwidth=0.8,relheight=0.4)
# Book ID to search
lb2 = Label(labelFrame,text="Book ID : ", bg='#222831', fg='white', font=('Consolas',13))
lb2.place(relx=0.05,rely=0.3)
bookInfo1 = Entry(labelFrame)
bookInfo1.place(relx=0.20,rely=0.3, relwidth=0.55)
Label(labelFrame, text="%-10s%-35s%-25s%-15s"%('BID','Title','Author','Status'),bg='#222831', fg='white', font=('Consolas',10)).place(relx=0.07,rely=0.5)
Label(labelFrame, text="--------------------------------------------------------------",bg='#222831', fg='white', font=('Consolas',12)).place(relx=0.05,rely=0.6)
def searchBook():
bookid = bookInfo1.get()
getBooks = "select * from "+bookTable+" where bookid = '"+bookid+"'"
y = 0.65
try:
cur.execute(getBooks)
con.commit()
for i in cur:
Label(labelFrame, text="%-10s%-35s%-25s%-15s"%(i[0],i[1],i[2],i[3]),bg='#222831', fg='white', font=('Consolas',10)).place(relx=0.07,rely=y)
y += 0.1
except:
messagebox.showinfo("Failed to fetch files from database")
#Submit Button
SearchBtn = Button(labelFrame,text="Search",bg='#F05454', fg='black', bd=0, font=('Consolas',13),command=searchBook)
SearchBtn.place(relx=0.77,rely=0.3, relwidth=0.12, relheight=0.06)
quitBtn = Button(root,text="Quit",bg='#F05454', fg='black', bd=0, font=('Consolas',13), command=root.destroy)
quitBtn.place(relx=0.37,rely=0.9, relwidth=0.28,relheight=0.08)
root.mainloop()