-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathReturn_gui.py
211 lines (163 loc) · 7.03 KB
/
Return_gui.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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import tkinter as t
from tkinter import scrolledtext as sct
from tkinter import messagebox,DoubleVar,ttk
import ListSplit_gui as ListSplit
import Borrow_details as BD
#these widgets and variables are declared global because they are
#used in multiple methods
global entry1,entry3
global entry2
global combo1
global scrollt
global btn
global btn1
global book_counter
book_counter=0
entry1=t.Entry()
entry2=t.Entry()
entry3=t.Entry()
btn=t.Button()
btn1=t.Button()
combo1=ttk.Combobox()
scrollt=sct.ScrolledText()
entry1_v=DoubleVar
entry2_v=DoubleVar
entry3_v=t.IntVar
#every global variable must be initialized before using
book_list=ListSplit.listSplit()
#r_window method generates the window used for book returning
def r_window():
global entry1
global entry2
global entry3
global combo1
global scrollt
global btn
global btn1
book_counter=0
window=t.Tk()
window.geometry("530x450")
window.title("Library management system")
window.resizable(0,1)
l1=t.Label(window,text="First Name",width=10).grid(row=0,pady=2,padx=4)
entry1=t.Entry(window,width=30,textvariable=entry1_v)
entry1.grid(row=0,column=1)
l2=t.Label(window,text="Last Name",width=10).grid(row=1,pady=2,padx=4)
entry2=t.Entry(window,width=30,textvariable=entry2_v)
entry2.grid(row=1,column=1)
btn=t.Button(window,text="Validate",command=validate,width=20)#validate() will be invoked when this button is clicked
btn.grid(row=2,columnspan=2,pady=5,padx=4)
scrollt=sct.ScrolledText(window,width=60,height=10)
scrollt.grid(row=4,rowspan=4,columnspan=3,padx=20,pady=2)
l3=t.Label(window,text="how many days was the book returned late").grid(row=8,pady=2,padx=4)
entry3=t.Entry(window,width=30,textvariable=entry3_v)
entry3.grid(row=8,column=1)
btn1=t.Button(window,text="Return",command=book_return,state=t.DISABLED,width=20)#winodw will be destroyed when this button is clicked
btn1.grid(row=9,columnspan=2,pady=2,padx=4)
window.mainloop()
#validate method is used to validate the returner's name and create his file
def validate():
global entry1
global entry2
global combo1
global scrollt
global btn,btn1
#retriving text entered in entry
firstName=str(entry1.get())
lastName=str(entry2.get())
a="F:\python projects\LMS\Borrow-"+firstName+" "+lastName+".txt"
b="F:\python projects\LMS\Return-"+firstName+" "+lastName+".txt"
#checking if the firstname and lastname contains only charachters and not numbers
if firstName.isalpha() and lastName.isalpha():
#checking if the user has borrowed any books or not
try:
#checking if borrowers file exists
with open(a,"r") as f:
lines=f.readlines()
#opening borrowers file
with open(a,"r") as f:
scrollt.delete(1.0,float(2000))
scrollt.update()
data=f.read()
scrollt.insert(t.INSERT,data)
t.messagebox.showinfo(message="File Opened successfully")
#checking if the borrower has returned the books or not
try:
#checking if returner's file exists
with open(b,"r") as f:
lines=f.readlines()
#opening the return and borrow files of user
with open(b,"r") as f,open(a,"r") as f1:
scrollt.delete(1.0,float(2000))
scrollt.update()
data=f1.read()
scrollt.insert(t.INSERT,data)
scrollt.insert(t.INSERT,"\n-------------------------------------------------------\n")
data1=f.read()
scrollt.insert(t.INSERT,data1)
t.messagebox.showinfo(message="The borrower has already returned the books")
except:
t.messagebox.showwarning(message="The borrower has not returned the books")
#activating the return button as borrower has not returned the books
btn1['state']=t.NORMAL
except:
#if borrower's file does not exists the name will be incorrect
t.messagebox.showwarning(message="The borrower name is incorrect")
else:
t.messagebox.showwarning(message="please input only alphabets from A-Z")
def book_return():
global entry1
global entry2,entry3
global combo1
global scrollt
global btn,btn1
firstName=str(entry1.get())
lastName=str(entry2.get())
a="F:\python projects\LMS\Borrow-"+firstName+" "+lastName+".txt"
b="F:\python projects\LMS\Return-"+firstName+" "+lastName+".txt"
#reading users book borrow file
with open(a,"r") as f1:
data2=f1.read()
#creating users book return file
with open(b,"w+")as f:
f.write(" Library Management System \n")
f.write(" Returned By: "+ firstName+" "+lastName+"\n")
f.write("S.N.\t\tBookname\t\tCost\n")
total=0.0
book_borrowed=BD.borrow_details(firstName,lastName)
count=0
for i in book_borrowed:
for j in range(ListSplit.count1):
if i == ListSplit.bookname[j]:
count+=1
with open(b,"a") as f:
f.write(str(count)+"\t\t"+ListSplit.bookname[j]+"\t\tRs"+ListSplit.cost[j]+"\n")
#adding 1 to book quntity on return
ListSplit.quantity[j]=int(ListSplit.quantity[j])+1
total+=float(ListSplit.cost[j])
if len(entry3.get()) == 0:
day=0
else:
day=int(entry3.get())
fine=5*day
#appending the fine to the users book return file
with open(b,"a")as f:
f.write("\t\t\t\t\tFine: Rs"+ str(fine)+"\n")
total=total+fine
t.messagebox.showinfo(title="Overflow",message="Total bill:"+str(total))
#appending the total cost to the users book return file
with open(b,"a")as f:
f.write("\t\t\t\t\tTotal: Rs"+ str(total))
#rewriting stocks after return of book
with open("F:\python projects\LMS\Stock.txt","w+") as f:
for i in range(ListSplit.count1):
f.write(ListSplit.bookname[i]+","+ListSplit.authorname[i]+","+str(ListSplit.quantity[i])+","+"Rs"+ListSplit.cost[i]+"\n")
#displaying the book return file of user in scrolledtext
b="F:\python projects\LMS\Return-"+firstName+" "+lastName+".txt"
with open(b,"r") as f:
scrollt.delete(1.0,float(2000))
scrollt.update()
data=f.read()
scrollt.insert(t.INSERT,data)
#when user returns the books the return button will be disabled
btn1['state']=t.DISABLED