-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdd_Books.py
54 lines (53 loc) · 2.4 KB
/
Add_Books.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
from tkinter import *
from tkinter import messagebox
import mysql.connector
from mysql.connector import Error
import os
import sys
py = sys.executable
#creating window
class Add(Tk):
def __init__(self):
super().__init__()
self.iconbitmap(r"import your favicon.ico path")
self.maxsize(480,360 )
self.minsize(480,360)
self.title('Add Book')
self.canvas = Canvas(width=500, height=500, bg='gray')
self.canvas.pack()
a = StringVar()
b = StringVar()
c = StringVar()
#verifying Input
def b_q():
if len(b.get()) == 0 or len(c.get()) == 0:
messagebox.showerror("Error","Please Enter The Details")
else:
g = 'YES'
try:
self.conn = mysql.connector.connect(host='localhost',
database='database_name',
user='username',
password='user password')
self.myCursor = self.conn.cursor()
self.myCursor.execute("Insert into book(name,author,availability) values (%s,%s,%s)",[b.get(),c.get(),g])
self.conn.commit()
messagebox.showinfo('Info', 'Succesfully Added')
ask = messagebox.askyesno("Confirm", "Do you want to add another book?")
if ask:
self.destroy()
os.system('%s %s' % (py, 'Add_Books.py'))
else:
self.destroy()
except Error:
messagebox.showerror("Error","Check The Details")
#creating input box and label
Label(self, text='').pack()
Label(self, text='Book Details:',bg='gray',fg='black',font=('Courier new', 20, 'bold')).place(x=150, y=70)
Label(self, text='').pack()
Label(self, text='Book Name:',bg='gray',fg='black', font=('Courier new', 10, 'bold')).place(x=60, y=180)
Entry(self, textvariable=b, width=30).place(x=170, y=182)
Label(self, text='Book Author:',bg='gray',fg='black', font=('Courier new', 10, 'bold')).place(x=60, y=230)
Entry(self, textvariable=c, width=30).place(x=170, y=232)
Button(self, text="Submit", command=b_q).place(x=245, y=300)
Add().mainloop()