|
1 | 1 | from tkinter import * |
2 | | -from PIL import ImageTk,Image |
| 2 | +from PIL import ImageTk, Image |
3 | 3 | from tkinter import messagebox |
4 | 4 | import pymysql |
5 | 5 |
|
| 6 | + |
6 | 7 | def bookRegister(): |
7 | | - |
| 8 | + |
8 | 9 | bid = bookInfo1.get() |
9 | 10 | title = bookInfo2.get() |
10 | 11 | author = bookInfo3.get() |
11 | 12 | status = bookInfo4.get() |
12 | 13 | status = status.lower() |
13 | | - |
14 | | - insertBooks = "insert into "+bookTable+" values('"+bid+"','"+title+"','"+author+"','"+status+"')" |
| 14 | + |
| 15 | + insertBooks = ( |
| 16 | + "insert into " |
| 17 | + + bookTable |
| 18 | + + " values('" |
| 19 | + + bid |
| 20 | + + "','" |
| 21 | + + title |
| 22 | + + "','" |
| 23 | + + author |
| 24 | + + "','" |
| 25 | + + status |
| 26 | + + "')" |
| 27 | + ) |
15 | 28 | try: |
16 | 29 | cur.execute(insertBooks) |
17 | 30 | con.commit() |
18 | | - messagebox.showinfo('Success',"Book added successfully") |
| 31 | + messagebox.showinfo("Success", "Book added successfully") |
19 | 32 | except: |
20 | | - messagebox.showinfo("Error","Can't add data into Database") |
21 | | - |
| 33 | + messagebox.showinfo("Error", "Can't add data into Database") |
| 34 | + |
22 | 35 | print(bid) |
23 | 36 | print(title) |
24 | 37 | print(author) |
25 | 38 | print(status) |
26 | 39 |
|
27 | | - |
28 | 40 | root.destroy() |
29 | | - |
30 | | -def addBook(): |
31 | | - |
32 | | - global bookInfo1,bookInfo2,bookInfo3,bookInfo4,Canvas1,con,cur,bookTable,root |
33 | | - |
| 41 | + |
| 42 | + |
| 43 | +def addBook(): |
| 44 | + |
| 45 | + global bookInfo1, bookInfo2, bookInfo3, bookInfo4, Canvas1, con, cur, bookTable, root |
| 46 | + |
34 | 47 | root = Tk() |
35 | 48 | root.title("Library") |
36 | | - root.minsize(width=400,height=400) |
| 49 | + root.minsize(width=400, height=400) |
37 | 50 | root.geometry("600x500") |
38 | 51 |
|
39 | 52 | # Add your own database name and password here to reflect in the code |
40 | 53 | mypass = "root" |
41 | | - mydatabase="db" |
| 54 | + mydatabase = "db" |
42 | 55 |
|
43 | | - con = pymysql.connect(host="localhost",user="root",password=mypass,database=mydatabase) |
| 56 | + con = pymysql.connect( |
| 57 | + host="localhost", user="root", password=mypass, database=mydatabase |
| 58 | + ) |
44 | 59 | cur = con.cursor() |
45 | 60 |
|
46 | 61 | # Enter Table Names here |
47 | | - bookTable = "books" # Book Table |
| 62 | + bookTable = "books" # Book Table |
48 | 63 |
|
49 | 64 | Canvas1 = Canvas(root) |
50 | | - |
| 65 | + |
51 | 66 | Canvas1.config(bg="#ff6e40") |
52 | | - Canvas1.pack(expand=True,fill=BOTH) |
53 | | - |
54 | | - headingFrame1 = Frame(root,bg="#FFBB00",bd=5) |
55 | | - headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheight=0.13) |
| 67 | + Canvas1.pack(expand=True, fill=BOTH) |
| 68 | + |
| 69 | + headingFrame1 = Frame(root, bg="#FFBB00", bd=5) |
| 70 | + headingFrame1.place(relx=0.25, rely=0.1, relwidth=0.5, relheight=0.13) |
56 | 71 |
|
57 | | - headingLabel = Label(headingFrame1, text="Add Books", bg='black', fg='white', font=('Courier',15)) |
58 | | - headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1) |
| 72 | + headingLabel = Label( |
| 73 | + headingFrame1, text="Add Books", bg="black", fg="white", font=("Courier", 15) |
| 74 | + ) |
| 75 | + headingLabel.place(relx=0, rely=0, relwidth=1, relheight=1) |
59 | 76 |
|
| 77 | + labelFrame = Frame(root, bg="black") |
| 78 | + labelFrame.place(relx=0.1, rely=0.4, relwidth=0.8, relheight=0.4) |
60 | 79 |
|
61 | | - labelFrame = Frame(root,bg='black') |
62 | | - labelFrame.place(relx=0.1,rely=0.4,relwidth=0.8,relheight=0.4) |
63 | | - |
64 | 80 | # Book ID |
65 | | - lb1 = Label(labelFrame,text="Book ID : ", bg='black', fg='white') |
66 | | - lb1.place(relx=0.05,rely=0.2, relheight=0.08) |
67 | | - |
| 81 | + lb1 = Label(labelFrame, text="Book ID : ", bg="black", fg="white") |
| 82 | + lb1.place(relx=0.05, rely=0.2, relheight=0.08) |
| 83 | + |
68 | 84 | bookInfo1 = Entry(labelFrame) |
69 | | - bookInfo1.place(relx=0.3,rely=0.2, relwidth=0.62, relheight=0.08) |
70 | | - |
| 85 | + bookInfo1.place(relx=0.3, rely=0.2, relwidth=0.62, relheight=0.08) |
| 86 | + |
71 | 87 | # Title |
72 | | - lb2 = Label(labelFrame,text="Title : ", bg='black', fg='white') |
73 | | - lb2.place(relx=0.05,rely=0.35, relheight=0.08) |
74 | | - |
| 88 | + lb2 = Label(labelFrame, text="Title : ", bg="black", fg="white") |
| 89 | + lb2.place(relx=0.05, rely=0.35, relheight=0.08) |
| 90 | + |
75 | 91 | bookInfo2 = Entry(labelFrame) |
76 | | - bookInfo2.place(relx=0.3,rely=0.35, relwidth=0.62, relheight=0.08) |
77 | | - |
| 92 | + bookInfo2.place(relx=0.3, rely=0.35, relwidth=0.62, relheight=0.08) |
| 93 | + |
78 | 94 | # Book Author |
79 | | - lb3 = Label(labelFrame,text="Author : ", bg='black', fg='white') |
80 | | - lb3.place(relx=0.05,rely=0.50, relheight=0.08) |
81 | | - |
| 95 | + lb3 = Label(labelFrame, text="Author : ", bg="black", fg="white") |
| 96 | + lb3.place(relx=0.05, rely=0.50, relheight=0.08) |
| 97 | + |
82 | 98 | bookInfo3 = Entry(labelFrame) |
83 | | - bookInfo3.place(relx=0.3,rely=0.50, relwidth=0.62, relheight=0.08) |
84 | | - |
| 99 | + bookInfo3.place(relx=0.3, rely=0.50, relwidth=0.62, relheight=0.08) |
| 100 | + |
85 | 101 | # Book Status |
86 | | - lb4 = Label(labelFrame,text="Status(Avail/issued) : ", bg='black', fg='white') |
87 | | - lb4.place(relx=0.05,rely=0.65, relheight=0.08) |
88 | | - |
| 102 | + lb4 = Label(labelFrame, text="Status(Avail/issued) : ", bg="black", fg="white") |
| 103 | + lb4.place(relx=0.05, rely=0.65, relheight=0.08) |
| 104 | + |
89 | 105 | bookInfo4 = Entry(labelFrame) |
90 | | - bookInfo4.place(relx=0.3,rely=0.65, relwidth=0.62, relheight=0.08) |
91 | | - |
92 | | - #Submit Button |
93 | | - SubmitBtn = Button(root,text="SUBMIT",bg='#d1ccc0', fg='black',command=bookRegister) |
94 | | - SubmitBtn.place(relx=0.28,rely=0.9, relwidth=0.18,relheight=0.08) |
95 | | - |
96 | | - quitBtn = Button(root,text="Quit",bg='#f7f1e3', fg='black', command=root.destroy) |
97 | | - quitBtn.place(relx=0.53,rely=0.9, relwidth=0.18,relheight=0.08) |
98 | | - |
| 106 | + bookInfo4.place(relx=0.3, rely=0.65, relwidth=0.62, relheight=0.08) |
| 107 | + |
| 108 | + # Submit Button |
| 109 | + SubmitBtn = Button( |
| 110 | + root, text="SUBMIT", bg="#d1ccc0", fg="black", command=bookRegister |
| 111 | + ) |
| 112 | + SubmitBtn.place(relx=0.28, rely=0.9, relwidth=0.18, relheight=0.08) |
| 113 | + |
| 114 | + quitBtn = Button(root, text="Quit", bg="#f7f1e3", fg="black", command=root.destroy) |
| 115 | + quitBtn.place(relx=0.53, rely=0.9, relwidth=0.18, relheight=0.08) |
| 116 | + |
99 | 117 | root.mainloop() |
0 commit comments