-
Notifications
You must be signed in to change notification settings - Fork 0
/
addbooks.py
91 lines (65 loc) · 2.93 KB
/
addbooks.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
79
80
81
82
83
84
85
86
87
88
89
90
91
from tkinter import *
from PIL import ImageTk,Image
from tkinter import messagebox
import sqlite3
import backend
"""
A function that is used to register a book.
"""
def bookRegister():
title = bookInfo2.get()
author = bookInfo3.get()
# insertBooks = "insert into "+bookTable+" values('"+bid+"','"+title+"','"+author+"','"+status+"')"
# Trying to insert the data into the database. If it fails, it will show an error message.
try:
backend.insert(title,author)
messagebox.showinfo('Success',"Book added successfully")
except:
messagebox.showinfo("Error","Can't add data into Database")
#print(bid)
print(title)
print(author)
#print(status)
root.destroy()
def addBook():
global bookInfo1,bookInfo2,bookInfo3,bookInfo4,Canvas1,con,cur,bookTable,root
root = Tk()
root.title("Library")
root.minsize(width=400,height=400)
root.geometry("600x500")
# Connecting to the database and creating a cursor.
con = sqlite3.connect("books.db")
cur = con.cursor()
# Enter Table Names here
bookTable = "books" # Book Table
Canvas1 = Canvas(root)
Canvas1.config(bg="#f0c575")
Canvas1.pack(expand=True,fill=BOTH)
headingFrame1 = Frame(root,bg="#9e5b09",bd=5)
headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheight=0.13)
headingLabel = Label(headingFrame1, text="Add Books", bg='black', fg='white', font=('Courier',23))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)
# Creating a frame and placing it in the window.
labelFrame = Frame(root,bg='black')
labelFrame.place(relx=0.1,rely=0.4,relwidth=0.8,relheight=0.3)
# Title
lb2 = Label(labelFrame,text="Title : ", bg='black', fg='white',font=(10))
lb2.place(relx=0.05,rely=0.35, relheight=0.12)
bookInfo2 = Entry(labelFrame)
bookInfo2.place(relx=0.25,rely=0.35, relwidth=0.62, relheight=0.12)
# Book Author
lb3 = Label(labelFrame,text="Author : ", bg='black', fg='white', font=(10))
lb3.place(relx=0.05,rely=0.60, relheight=0.12)
bookInfo3 = Entry(labelFrame)
bookInfo3.place(relx=0.25,rely=0.60, relwidth=0.62, relheight=0.12)
# Book Status
"""lb4 = Label(labelFrame,text="Status(Avail/issued) : ", bg='black', fg='white')
lb4.place(relx=0.05,rely=0.65, relheight=0.08)
bookInfo4 = Entry(labelFrame)
bookInfo4.place(relx=0.3,rely=0.65, relwidth=0.62, relheight=0.08)"""
#Submit Button
SubmitBtn = Button(root,text="SUBMIT",bg='#d1ccc0', fg='black',command=bookRegister)
SubmitBtn.place(relx=0.28,rely=0.9, relwidth=0.18,relheight=0.08)
quitBtn = Button(root,text="Quit",bg='#f7f1e3', fg='black', command=root.destroy)
quitBtn.place(relx=0.53,rely=0.9, relwidth=0.18,relheight=0.08)
root.mainloop()