-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_book.py
More file actions
77 lines (72 loc) · 2.3 KB
/
Copy pathadd_book.py
File metadata and controls
77 lines (72 loc) · 2.3 KB
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
from tkinter import *
import pymysql
from tkinter import messagebox
from connect_db import connect
def add_books(home, add_book):
add_book.configure(background="black")
Label(add_book, text="Add Book", bg="black", fg="white", font=("Courier", 35)).pack(
pady=15
)
Label(add_book, text="Book Id", bg="black", fg="white", font=("Courier", 25)).pack(
pady=5
)
id = Text(add_book, height=1, width=30, font=("Courier", 25))
id.pack(pady=5)
Label(add_book, text="Name", bg="black", fg="white", font=("Courier", 25)).pack(
pady=5
)
name = Text(add_book, height=1, width=30, font=("Courier", 25))
name.pack(pady=5)
Label(add_book, text="Author", bg="black", fg="white", font=("Courier", 25)).pack(
pady=5
)
author = Text(add_book, height=1, width=30, font=("Courier", 25))
author.pack(pady=5)
Label(add_book, text="Category", bg="black", fg="white", font=("Courier", 25)).pack(
pady=5
)
category = Text(add_book, height=1, width=30, font=("Courier", 25))
category.pack(pady=5)
Label(add_book, text="Count", bg="black", fg="white", font=("Courier", 25)).pack(
pady=5
)
count = Text(add_book, height=1, width=30, font=("Courier", 25))
count.pack()
Button(
add_book,
text="Submit",
command=lambda: add_book_query(id, name, category, author, count),
bg="black",
fg="white",
font=("Courier", 25),
).pack(pady=12)
add_book.pack(expand=1, fill=X)
home.pack_forget()
def add_book_query(id, name, category, author, count):
book_id = id.get(1.0, "end-1c")
name = name.get(1.0, "end-1c")
category = category.get(1.0, "end-1c")
author = author.get(1.0, "end-1c")
count = count.get(1.0, "end-1c")
print(book_id, name, category, author, count)
insert = (
"insert into Books values("
+ book_id
+ ",'"
+ name
+ "','"
+ author
+ "', '"
+ category
+ "',"
+ count
+ ","
+ count
+ ");"
)
try:
connect(insert)
messagebox.showinfo("Success", "Book added successfully")
except (pymysql.Error, pymysql.Warning) as e:
err = str(e)
messagebox.showinfo("Error", "Can't add data into Database " + err)