-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainModule.py
More file actions
187 lines (163 loc) · 8.85 KB
/
MainModule.py
File metadata and controls
187 lines (163 loc) · 8.85 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
from tkinter import *
from tkinter import messagebox
import os
import sys
from tkinter import ttk
import mysql.connector
from mysql.connector import Error
py=sys.executable
#creating window
class MainWin(Tk):
def __init__(self):
super().__init__()
self.iconbitmap(r"import your favicon.ico path")
self.configure(bg='gray')
self.canvas = Canvas(width=1366, height=768, bg='gray')
self.canvas.pack()
self.maxsize(1320, 768)
self.minsize(1320,768)
self.state('zoomed')
self.title('LIBRARY MANAGEMENT SYSTEMS')
self.a = StringVar()
self.b = StringVar()
self.mymenu = Menu(self)
#calling scripts
def a_s():
os.system('%s %s' % (py, 'Add_Student.py'))
def a_b():
os.system('%s %s' % (py, 'Add_Books.py'))
def r_b():
os.system('%s %s' % (py, 'remove_book.py'))
def r_s():
os.system('%s %s' % (py, 'Remove_student.py'))
def ib():
os.system('%s %s' % (py, 'IssueBook.py'))
def ret():
os.system('%s %s' % (py, 'ReturnBook.py'))
def sea():
os.system('%s %s' % (py,'SearchBook.py'))
def log():
conf = messagebox.askyesno("Confirm", "Are you sure you want to Logout?")
if conf:
self.destroy()
os.system('%s %s' % (py, 'Login.py'))
# def handle(event):
# if self.listTree.identify_region(event.x,event.y) == "separator":
# return "break"
def add_user():
os.system('%s %s' % (py, 'Add_Student.py'))
def rem_user():
os.system('%s %s' % (py, 'Remove_student.py'))
def sest():
os.system('%s %s' % (py,'Search_Student.py'))
#creating table
self.listTree = ttk.Treeview(self,height=14,columns=('Student','Book','Issue Date','Return Date'))
self.vsb = ttk.Scrollbar(self,orient="vertical",command=self.listTree.yview)
self.hsb = ttk.Scrollbar(self,orient="horizontal",command=self.listTree.xview)
self.listTree.configure(yscrollcommand=self.vsb.set,xscrollcommand=self.hsb.set)
self.listTree.heading("#0", text='ID')
self.listTree.column("#0", width=50,minwidth=50,anchor='center')
self.listTree.heading("Student", text='Student')
self.listTree.column("Student", width=200, minwidth=200,anchor='center')
self.listTree.heading("Book", text='Book')
self.listTree.column("Book", width=200, minwidth=200,anchor='center')
self.listTree.heading("Issue Date", text='Issue Date')
self.listTree.column("Issue Date", width=125, minwidth=125,anchor='center')
self.listTree.heading("Return Date", text='Return Date')
self.listTree.column("Return Date", width=125, minwidth=125, anchor='center')
self.listTree.place(x=320,y=360)
self.vsb.place(x=1028,y=361,height=287)
self.hsb.place(x=320,y=650,width=700)
ttk.Style().configure("Treeview",font=('Times new Roman',15))
list1 = Menu(self)
list1.add_command(label="Student", command=a_s)
list1.add_command(label="Book", command=a_b)
list3 = Menu(self)
list3.add_command(label = "Add User",command = add_user)
list3.add_command(label = "Remove User",command = rem_user)
self.mymenu.add_cascade(label='Add', menu=list1)
self.mymenu.add_cascade(label = 'Admin Tools', menu = list3)
self.config(menu=self.mymenu)
def ser():
if(len(self.studid.get())==0):
messagebox.showinfo("Error", "Empty Field!")
else:
try:
conn = mysql.connector.connect(host='localhost',
database='library',
user='root',
password='tanu1620')
cursor = conn.cursor()
change = int(self.studid.get())
cursor.execute("Select bi.issue_id,s.name,b.name,bi.issue_date,bi.return_date from issue_book bi,student s,book b where s.stud_id = bi.stud_id and b.book_id = bi.book_id and s.stud_id = %s",[change])
pc = cursor.fetchall()
if pc:
self.listTree.delete(*self.listTree.get_children())
for row in pc:
self.listTree.insert("",'end',text=row[0] ,values = (row[1],row[2],row[3],row[4]))
else:
messagebox.showinfo("Error", "Either ID is wrong or The book is not yet issued on this ID")
except Error:
#print(Error)
messagebox.showerror("Error","Something Goes Wrong")
def ent():
if (len(self.bookid.get()) == 0):
messagebox.showinfo("Error", "Empty Field!")
else:
try:
self.conn = mysql.connector.connect(host='localhost',
database='database_name',
user='username',
password='user password')
self.myCursor = self.conn.cursor()
book = int(self.bookid.get())
self.myCursor.execute("Select bi.issue_id,s.name,b.name,bi.issue_date,bi.return_date from issue_book bi,student s,book b where s.stud_id = bi.stud_id and b.book_id = bi.book_id and b.book_id = %s",[book])
self.pc = self.myCursor.fetchall()
if self.pc:
self.listTree.delete(*self.listTree.get_children())
for row in self.pc:
self.listTree.insert("", 'end', text=row[0],values=(row[1], row[2], row[3], row[4]))
else:
messagebox.showinfo("Error", "Either ID is wrong or The book is not yet issued")
except Error:
messagebox.showerror("Error", "Something Goes Wrong")
def check():
try:
conn = mysql.connector.connect(host='localhost',
database='database_name',
user='username',
password='user password')
mycursor = conn.cursor()
mycursor.execute("Select * from admin")
z = mycursor.fetchone()
if not z:
messagebox.showinfo("Error", "Please Register A user")
x = messagebox.askyesno("Confirm","Do you want to register a user")
if x:
self.destroy()
os.system('%s %s' % (py, 'Reg.py'))
else:
#label and input box
self.label3 = Label(self, text='LIBRARY MANAGEMENT SYSTEM',fg='black',bg="gray" ,font=('Courier new', 30, 'bold'))
self.label3.place(x=350, y=22)
self.label4 = Label(self, text="ENTER STUDENT",bg="gray", font=('Courier new', 18, 'bold'))
self.label4.place(x=130, y=107)
self.studid = Entry(self, textvariable=self.a, width=90)
self.studid.place(x=405, y=110)
self.srt = Button(self, text='Search', width=15, font=('arial', 10),command = ser).place(x=1000, y=106)
self.label5 = Label(self, text="ENTER THE BOOK ID",bg="gray", font=('Courier new', 18, 'bold'))
self.label5.place(x=75, y=150)
self.bookid = Entry(self, textvariable=self.b, width=90)
self.bookid.place(x=405, y=160)
self.brt = Button(self, text='Find', width=15, font=('arial', 10),command = ent).place(x=1000, y=150)
self.label6 = Label(self, text="INFORMATION DETAILS",bg="gray", font=('Courier new', 15, 'underline', 'bold'))
self.label6.place(x=560, y=300)
self.button = Button(self, text='Search Student', width=25, font=('Courier new', 10), command=sest).place(x=240,y=250)
self.button = Button(self, text='Search Book', width=25, font=('Courier new', 10), command=sea).place(x=520,y=250)
self.brt = Button(self, text="Issue Book", width=15, font=('Courier new', 10), command=ib).place(x=800, y=250)
self.brt = Button(self, text="Return Book", width=15, font=('Courier new', 10), command=ret).place(x=1000, y=250)
self.brt = Button(self, text="LOGOUT", width=15,bg="red", font=('Courier new', 10), command=log).place(x=1150, y=105)
except Error:
messagebox.showerror("Error", "Something Goes Wrong")
check()
MainWin().mainloop()