-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.py
More file actions
287 lines (223 loc) · 10.2 KB
/
Copy pathsearch.py
File metadata and controls
287 lines (223 loc) · 10.2 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
import tkinter as tk
from tkinter import ttk
import users
import operation
from Select import *
DIR = {'人文': 0, '艺术': 1, '计算机': 2, '科技': 3, '杂志': 4, '其他': 5}
# ---------------------------------------------------------------------------------------------------
# 用户部分
def users_search(stu): # 用户查询界面
global gg
gg = tk.Tk()
gg.title('查询书籍(用户)')
gg.geometry('700x600')
label0 = tk.Label(gg, text='欢迎来到JXNU图书馆', bg='pink', font=('微软雅黑', 50)).pack()
label1 = tk.Label(gg, text='请选择查询方式:', font=('微软雅黑', 20)).place(x=80, y=200)
botton1 = tk.Button(gg, text='按类别查询', font=('微软雅黑', 25), command=lambda: users_book_type(stu)).place(x=280, y=250)
botton2 = tk.Button(gg, text='按书名查询', font=('微软雅黑', 25), command=lambda: users_book_name(stu)).place(x=280, y=350)
botton3 = tk.Button(gg, text='按作者查询', font=('微软雅黑', 25), command=lambda: users_author_name(stu)).place(x=280, y=450)
botton4 = tk.Button(gg, text='返回', font=('微软雅黑', 15), command=lambda: exit1(stu)).place(x=600, y=500)
gg.mainloop()
def users_book_type(stu): # 类型查询(用户)
gg.destroy()
global gg1
gg1 = tk.Tk()
gg1.wm_attributes('-topmost', 1)
gg1.title('查询')
gg1.geometry('300x200')
tk.Label(gg1, text='图书类目:', font=('宋体', 12)).place(x=40, y=50)
global list # 这个是一个下拉页表项,只能从下面的list['values']里边选
comvalue = tk.StringVar()
list = ttk.Combobox(gg1, textvariable=comvalue, height=10, width=10)
list.place(x=115, y=50)
list['values'] = ('人文', '艺术', '计算机', '科技', '杂志')
list.current(0) # 默认显示'人文'
data = GetBookByBookType(DIR[list.get()])
tk.Button(gg1, text='确认', font=('宋体', 12), width=10, command=lambda: users_search_result1(stu, data)).place(x=150,
y=125)
def Mid1(stu, bookname):
data = GetBookByBookname(bookname.get())
users_search_result2(stu, data)
def users_book_name(stu): # 书名查询(用户)
gg.destroy()
global gg2
gg2 = tk.Tk()
gg2.wm_attributes('-topmost', 1)
gg2.title('查询')
gg2.geometry('300x200')
global bookname
N = tk.StringVar()
tk.Label(gg2, text='书名:', font=('宋体', 12)).place(x=40, y=50)
bookname = tk.Entry(gg2, textvariable=N, font=('宋体', 12), width=10)
bookname.place(x=90, y=50)
tk.Button(gg2, text='确认', font=('宋体', 12), width=10,
command=lambda: Mid1(stu, bookname)).place(x=150, y=125)
def Mid2(stu, author):
data = GetBookByBookAuthor(author.get())
users_search_result3(stu, data)
def users_author_name(stu): # 作者查询(用户)
gg.destroy()
global gg3
gg3 = tk.Tk()
gg3.wm_attributes('-topmost', 1)
gg3.title('查询')
gg3.geometry('300x200')
global author
A = tk.StringVar()
tk.Label(gg3, text='作者:', font=('宋体', 12)).place(x=40, y=50)
author = tk.Entry(gg3, textvariable=A, font=('宋体', 12), width=10)
author.place(x=90, y=50)
tk.Button(gg3, text='确认', font=('宋体', 12), width=10, command=lambda: Mid2(stu, author)).place(x=150, y=125)
def search_result1(stu, data): # 用户查询结果页面
global gg4
gg4 = tk.Tk()
gg4.title('查询结果')
gg4.geometry('900x500')
label0 = tk.Label(gg4, text='欢迎来到JXNU图书馆', bg='pink', font=('微软雅黑', 50)).pack()
# 创建一个表格
tree = ttk.Treeview(gg4, columns=('2', '3', '4', '5', '6', '7'), show='headings')
tree.column('2', width=100, anchor='center')
tree.column('3', width=100, anchor='center')
tree.column('4', width=100, anchor='center')
tree.column('5', width=100, anchor='center')
tree.column('6', width=100, anchor='center')
tree.column('7', width=100, anchor='center')
tree.heading('2', text='书名')
tree.heading('3', text='作者')
tree.heading('4', text='数量')
tree.heading('5', text='价格')
tree.heading('6', text='类别')
tree.heading('7', text='可借期限')
# 测试数据
print(data)
sales_data = data
# 将测试数据添加到表格中
for i in sales_data:
tree.insert('', 'end', values=i)
# 此处用函数获取数据后,将其insert 到上面的表格中
tree.place(x=140, y=100)
tk.Button(gg4, text='返 回', font=('微软雅黑', 15), command=lambda: exit_search1(stu)).place(x=800, y=400)
gg4.mainloop()
def users_search_result1(stu, data): # 按类型查询结果(用户)
gg1.destroy()
search_result1(stu, data)
def users_search_result2(stu, data): # 按书名查询结果(用户)
gg2.destroy()
search_result1(stu, data)
def users_search_result3(stu, data): # 按作者查询结果(用户)
gg3.destroy()
search_result1(stu, data)
# --------------------------------------------------------------------------------------
# 管理员部分
def operation_search(): # 管理员查询界面
global GG
GG = tk.Tk()
GG.title('查询书籍(管理员)')
GG.geometry('700x600')
label0 = tk.Label(GG, text='欢迎来到JXNU图书馆', bg='pink', font=('微软雅黑', 50)).pack()
label1 = tk.Label(GG, text='请选择查询方式:', font=('微软雅黑', 20)).place(x=80, y=200)
botton1 = tk.Button(GG, text='按类别查询', font=('微软雅黑', 25), command=operation_book_type).place(x=280, y=250)
botton2 = tk.Button(GG, text='按书名查询', font=('微软雅黑', 25), command=operation_book_name).place(x=280, y=350)
botton3 = tk.Button(GG, text='按作者查询', font=('微软雅黑', 25), command=operation_author_name).place(x=280, y=450)
botton4 = tk.Button(GG, text='返回', font=('微软雅黑', 15), command=exit2).place(x=600, y=500)
GG.mainloop()
def operation_book_type(): # 类型查询(管理员)
GG.destroy()
global GG1
GG1 = tk.Tk()
GG1.wm_attributes('-topmost', 1) # 窗口置顶
GG1.title('查询')
GG1.geometry('300x200')
tk.Label(GG1, text='图书类目:', font=('宋体', 12)).place(x=40, y=50)
global list # 这个是一个下拉页表项,只能从下面的list['values']里边选
comvalue = tk.StringVar()
list = ttk.Combobox(GG1, textvariable=comvalue, height=10, width=10)
list.place(x=115, y=50)
list['values'] = ('人文', '艺术', '计算机', '科技', '杂志')
list.current(0) # 默认显示'人文'
data = GetBookByBookType(DIR[list.get()])
tk.Button(GG1, text='确认', font=('宋体', 12), width=10, command=lambda: operation_search_result1(data)).place(x=150,
y=125)
def operation_book_name(): # 书名查询(管理员)
GG.destroy()
global GG2
GG2 = tk.Tk()
GG2.wm_attributes('-topmost', 1)
GG2.title('查询')
GG2.geometry('300x200')
global bookname
N = tk.StringVar()
tk.Label(GG2, text='书名:', font=('宋体', 12)).place(x=40, y=50)
bookname = tk.Entry(GG2, textvariable=N, font=('宋体', 12), width=10)
bookname.place(x=90, y=50)
# data = GetBookByBookname(bookname.get())
B = tk.Button(GG2, text='确认', font=('宋体', 12), width=10, command=lambda: mid1(bookname)).place(x=150, y=125)
def mid1(bookname):
data = GetBookByBookname(bookname.get())
operation_search_result2(data)
def operation_author_name(): # 作者查询(管理员)
GG.destroy()
global GG3
GG3 = tk.Tk()
GG3.wm_attributes('-topmost', 1)
GG3.title('查询')
GG3.geometry('300x200')
global author
tk.Label(GG3, text='作者:', font=('宋体', 12)).place(x=40, y=50)
author = tk.Entry(GG3, font=('宋体', 12), width=10)
author.place(x=90, y=50)
tk.Button(GG3, text='确认', font=('宋体', 12), width=10, command=lambda: mid2(author)).place(x=150, y=125)
def mid2(author): # 跳转函数
data = GetBookByBookAuthor(author.get())
operation_search_result3(data)
def search_result2(data): # 管理员查询结果页面
global GG4
GG4 = tk.Tk()
GG4.title('查询结果')
GG4.geometry('900x500')
label0 = tk.Label(GG4, text='欢迎来到JXNU图书馆', bg='pink', font=('微软雅黑', 50)).pack()
# 创建一个表格
tree = ttk.Treeview(GG4, columns=( '2', '3', '4', '5', '6', '7'), show='headings')
tree.column('2', width=100, anchor='center')
tree.column('3', width=100, anchor='center')
tree.column('4', width=100, anchor='center')
tree.column('5', width=100, anchor='center')
tree.column('6', width=100, anchor='center')
tree.column('7', width=100, anchor='center')
tree.heading('2', text='书名')
tree.heading('3', text='作者')
tree.heading('4', text='数量')
tree.heading('5', text='价格')
tree.heading('6', text='类别')
tree.heading('7', text='可借期限')
# 测试数据
sales_data = data
# 将测试数据添加到表格中
for i in sales_data:
tree.insert('', 'end', values=i)
# 同上(用户部分),用函数读取数据,并 insert 至 上面的表格中
tree.place(x=140, y=100)
tk.Button(GG4, text='返 回', font=('微软雅黑', 15), command=exit_search2).place(x=800, y=400)
GG4.mainloop()
def operation_search_result1(data): # 按类型查询结果(管理员)
GG1.destroy()
search_result2(data)
def operation_search_result2(data): # 按书名查询结果(管理员)
GG2.destroy()
search_result2(data)
def operation_search_result3(data): # 按作者查询结果(管理员)
GG3.destroy()
search_result2(data)
# -------------------------------------------------------------------------------------------------------
def exit_search1(stu): # 回到用户查询界面
gg4.destroy()
users_search(stu)
def exit_search2(): # 回到管理员查询选择界面
GG4.destroy()
operation_search()
def exit1(stu): # 回到用户界面
gg.destroy()
users.frame(stu)
def exit2(): # 回到管理员界面
GG.destroy()
operation.frame()