当前位置:   article > 正文

python图书管理系统设计,python写图书管理系统_python设计一个图书管理系统的窗口

python设计一个图书管理系统的窗口

大家好,小编来为大家解答以下问题,如何python图书管理系统界面,图书管理系统登录界面python,现在让我们一起来看看吧!

图书管理系统:界面设计的比较丑请忽略
数据要求
根据系统的需求,将需要的数据分类记录如下:
(1) 图书信息:编号、名称、储量、作者、出版时间
(2) 图书借阅信息:读者学号、图书编号、记录编号、借书日期、还书日期
(3) 读者信息:学号、姓名、性别、班级、剩余最大借书量
(4) 管理者信息:管理者姓名、职工号、权限级别

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  1. import tkinter as tk
  2. import tkinter.messagebox as msg
  3. import pymysql
  4. import os
  5. BACK_PATH="resources"+os.sep+"background.gif"
  6. def check_book():
  7. db = pymysql.connect("localhost", "root", "*****", "library")
  8. cursor = db.cursor()
  9. a = input_book.get()
  10. sql = "SELECT * FROM book WHERE bname = '%s'" % (a)
  11. cursor.execute(sql)
  12. results = cursor.fetchone()
  13. if results:
  14. root3 = tk.Tk()
  15. root3.title('查询到的书')
  16. val = "您要查询的书号为:%s" % (results[0])
  17. print1 = tk.Label(root3, text=val)
  18. print1.grid(row=0, column=0, padx=10, pady=5)
  19. val = "您要查询的书号为:%s" % (results[0])
  20. print2 = tk.Label(root3, text=val)
  21. print2.grid(row=1, column=0, padx=10, pady=5)
  22. val = "您要查询的书的作者为:%s" % (results[1])
  23. print3 = tk.Label(root3, text=val)
  24. print3.grid(row=2, column=0, padx=10, pady=5)
  25. val = "您要查询的书的作者为:%s" % (results[2])
  26. print4 = tk.Label(root3, text=val)
  27. print4.grid(row=3, column=0, padx=10, pady=5)
  28. val = "您要查询的书名为:%s" % (results[3])
  29. print5 = tk.Label(root3, text=val)
  30. print5.grid(row=4, column=0, padx=10, pady=5)
  31. val = "您要查询的书的出版日期为:%s" % (results[4])
  32. print6 = tk.Label(root3, text=val)
  33. print6.grid(row=5, column=0, padx=10, pady=5)
  34. else:
  35. msg._show(title='错误', message='没有查到您要查询的记录')
  36. db.close()
  37. def borrow_end():
  38. db = pymysql.connect("localhost", "root", "*****", "library")
  39. cursor = db.cursor()
  40. id = input_id.get()
  41. name = input8.get()
  42. sql = "SELECT bid,num FROM book WHERE bname='%s'" % (name)
  43. cursor.execute(sql)
  44. results = cursor.fetchone()
  45. if results[1] > 0:
  46. sql = "INSERT INTO borrow(rid,bid,btime) VALUES(%s,%s,CURDATE())" % (id, results[0])
  47. try:
  48. cursor.execute(sql)
  49. db.commit()
  50. msg._show(title="成功",message="借阅成功!")
  51. except:
  52. msg._show(title="系统故障",message="借阅失败!")
  53. else:
  54. msg._show(title="库存量不足",message="对不起,您要借阅的图书库存不足!")
  55. db.close()
  56. def return_end():
  57. db = pymysql.connect("localhost", "root", "*****", "library")
  58. cursor = db.cursor()
  59. id = input_id.get()
  60. name = input9.get()
  61. sql = "SELECT bid FROM book WHERE bname = '%s'" % (name)
  62. cursor.execute(sql)
  63. results = cursor.fetchone()
  64. sql = "SELECT lid FROM borrow WHERE bid=%s AND rid=%s" % (results[0], id)
  65. cursor.execute(sql)
  66. result = cursor.fetchone()
  67. sql = "UPDATE borrow SET rtime=CURDATE()WHERE lid= %s"%(result[0])
  68. try:
  69. cursor.execute(sql)
  70. db.commit()
  71. msg._show(title='成功',message='还书成功')
  72. except:
  73. msg._show(title='系统故障',message='还失败')
  74. db.close()
  75. def donate_end():
  76. db = pymysql.connect("localhost", "root", "*****", "library")
  77. cursor = db.cursor()
  78. id = input_id.get()
  79. name = input10.get()
  80. amount = input11.get()
  81. write = input12.get()
  82. tim= input13.get()
  83. sql = "SELECT num FROM book WHERE bname='%s'" % (name)
  84. cursor.execute(sql)
  85. results = cursor.fetchone()
  86. if results:
  87. sql = "UPDATE book SET num=num+%s WHERE bname='%s'" % (amount, name)
  88. try:
  89. cursor.execute(sql)
  90. db.commit()
  91. msg._show(title="成功",message="捐书成功!谢谢您")
  92. except:
  93. msg._show(title="系统故障",message="捐书失败")
  94. db.rollback()
  95. else:
  96. sql = "SELECT MAX(bid) FROM book"
  97. cursor.execute(sql)
  98. results = cursor.fetchone()
  99. results[0] = results[0] + 1
  100. sql = "INSERT INTO book VALUES (%s,'%s',%s,'%s','%s')" % (results, write, amount, name, tim)
  101. try:
  102. cursor.execute(sql)
  103. db.commit()
  104. msg._show(title="成功", message="捐书成功!谢谢您")
  105. except:
  106. msg._show(title="错误", message="输入信息有误")
  107. db.rollback()
  108. db.close()
  109. def book_select():
  110. v1=tk.StringVar()
  111. global root2
  112. root2=tk.Tk()
  113. root2.title("查询图书")
  114. global input_book
  115. labe1 = tk.Label(root2, text="请输入您要查询的图书名:", font=36).grid(row=0, column=0)
  116. input_book = tk.Entry(root2,textvariable=v1)
  117. input_book.grid(row=0,column=1)
  118. tk.Button(root2, text='确认', width=10, command=check_book).grid(row=1, column=0, sticky=tk.W, padx=10, pady=5)
  119. tk.Button(root2, text='取消', width=10, command=exit_login3).grid(row=1, column=1, sticky=tk.E, padx=10, pady=5)
  120. def book_borrow():
  121. db = pymysql.connect("localhost", "root", "*****", "library")
  122. cursor = db.cursor()
  123. id=input_id.get()
  124. sql = "SELECT bleft FROM reader WHERE rid = %s" % (id)
  125. cursor.execute(sql)
  126. result = cursor.fetchone()
  127. v_borrow=tk.StringVar()
  128. if result[0] == 0:
  129. msg._show(title="错误",message="你已达最大借阅量,借阅失败")
  130. global root2
  131. root2 = tk.Tk()
  132. root2 .title("借阅")
  133. global input8
  134. labe1 = tk.Label(root2, text="请输入您要借阅的图书名:", font=36).grid(row=0, column=0)
  135. input8 = tk.Entry(root2, textvariable=v_borrow)
  136. input8.grid(row=1,column=0)
  137. tk.Button(root2, text='确认', width=10, command=borrow_end).grid(row=2, column=0, sticky=tk.W, padx=10, pady=5)
  138. tk.Button(root2, text='取消', width=10, command=exit_login3).grid(row=2, column=1, sticky=tk.E, padx=10, pady=5)
  139. db.close()
  140. def return_book():
  141. global root2
  142. root2 = tk.Tk()
  143. root2.title("还书")
  144. v1=tk.StringVar()
  145. global input9
  146. labe1 = tk.Label(root2, text="请输入您要还的图书名:", font=36).grid(row=0, column=0)
  147. input9 = tk.Entry(root2, textvariable=v1)
  148. input9.grid(row=1, column=0)
  149. tk.Button(root2, text='确认', width=10, command=return_end).grid(row=2, column=0, sticky=tk.W, padx=10, pady=5)
  150. tk.Button(root2, text='取消', width=10, command=exit_login3).grid(row=2, column=1, sticky=tk.E, padx=10, pady=5)
  151. def donate_book():
  152. global root2
  153. root2 = tk.Tk()
  154. root2.title("捐书")
  155. v1 = tk.StringVar()
  156. v2 = tk.StringVar()
  157. v3 = tk.StringVar()
  158. v4 = tk.StringVar()
  159. global input10,input11,input12,input13
  160. labe1 = tk.Label(root2, text="请输入您要捐赠的图书名:", font=36).grid(row=0, column=0)
  161. labe12 = tk.Label(root2, text="请输入您要捐赠的图书的数量:", font=36).grid(row=1, column=0)
  162. labe13 = tk.Label(root2, text="请输入您要捐赠的作者:", font=36).grid(row=2, column=0)
  163. labe4 = tk.Label(root2, text="请输入您要捐赠的图书的出版时间:", font=36).grid(row=3, column=0)
  164. input10 = tk.Entry(root2, textvariable=v1)
  165. input10.grid(row=0, column=1)
  166. input11 = tk.Entry(root2, textvariable=v2)
  167. input11.grid(row=1, column=1)
  168. input12 = tk.Entry(root2, textvariable=v3)
  169. input12.grid(row=2, column=1)
  170. input13 = tk.Entry(root2, textvariable=v4)
  171. input13.grid(row=3, column=1)
  172. tk.Button(root2, text='确认', width=10, command=donate_end).grid(row=4, column=0, sticky=tk.W, padx=10, pady=5)
  173. tk.Button(root2, text='取消', width=10, command=exit_login3).grid(row=4, column=1, sticky=tk.E, padx=10, pady=5)
  174. def success_tip(id):
  175. root1 = tk.Tk()
  176. root1.title('YTU图书管理系统')
  177. labe1 = tk.Label(root1, text="欢迎来到YTU图书管理系统,请选择您要进行的操作:", font=36).grid(row=0, column=0)
  178. tk.Button(root1, text='查询图书', command=book_select).grid(row=1, column=0)
  179. tk.Button(root1, text='借阅图书', command=book_borrow).grid(row=2, column=0)
  180. tk.Button(root1, text='归还图书', command=return_book).grid(row=3, column=0)
  181. tk.Button(root1, text='捐赠图书', command=donate_book).grid(row=4, column=0)
  182. tk.Button(root1, text='退出', command=resiger).grid(row=5, column=0)
  183. root1.mainloop()
  184. def exit_login2():
  185. root1.destroy()
  186. def login_check():
  187. db = pymysql.connect("localhost", "root", "*****", "library")
  188. cursor = db.cursor()
  189. id=input_id.get()
  190. name=input2.get()
  191. sql = "SELECT rname FROM reader WHERE rid='%s'" % (id)
  192. cursor.execute(sql)
  193. results = cursor.fetchone()
  194. if results:
  195. if name == results[0]:
  196. success_tip(id)
  197. else:
  198. msg._show(title='错误!',message='账号密码输入错误!')
  199. else:
  200. msg._show(title='错误!',message='您输入的用户不存在!')
  201. db.close()
  202. def auto_login():
  203. global root1
  204. root1 = tk.Tk()
  205. v1 = tk.StringVar()
  206. v2 = tk.StringVar()
  207. root1.title("登入")
  208. labe1=tk.Label(root1,text="学号:",font=36).grid(row=0, column=0)
  209. label2=tk.Label(root1,text="密码:",font=36).grid(row=1,column=0)
  210. global input_id,input2
  211. input_id = tk.Entry(root1, textvariable=v1)
  212. input_id.grid(row=0, column=1, padx=10, pady=5)
  213. input2 = tk.Entry(root1, textvariable=v2, show='*')
  214. input2.grid(row=1, column=1, padx=10, pady=5)
  215. tk.Button(root1, text='登录', width=10, command=login_check).grid(row=3, column=0, sticky=tk.W, padx=10, pady=5)
  216. tk.Button(root1, text='退出', width=10, command=exit_login2).grid(row=3, column=1, sticky=tk.E, padx=10, pady=5)
  217. def exit_login():
  218. root.destroy()
  219. def exit_login3():
  220. root2.destroy()
  221. def resiger_end():
  222. db = pymysql.connect("localhost", "root", "*****", "library")
  223. cursor = db.cursor()
  224. rid = input1.get()
  225. name = input2.get()
  226. sex = input3.get()
  227. clas = input4.get()
  228. sql = "INSERT INTO reader VALUES(%s,'%s','%s','%s',10)" % (rid, name, sex, clas)
  229. try:
  230. cursor.execute(sql)
  231. db.commit()
  232. msg._show(title='成功', message='注册成功!')
  233. except:
  234. msg._show(title='错误', message='注册失败!')
  235. db.close()
  236. def resiger():
  237. root2 = tk.Tk()
  238. root2.title("注册")
  239. labe1 = tk.Label(root2, text="学号:", font=36).grid(row=0,column=0)
  240. label2 = tk.Label(root2, text="密码:", font=36).grid(row=1,column=0)
  241. label3 = tk.Label(root2,text="性别:",font=36).grid(row=2,column=0)
  242. label4 = tk.Label(root2,text="班级:",font=36).grid(row=3,column=0)
  243. v1 = tk.StringVar()
  244. v2 = tk.StringVar()
  245. v3 = tk.StringVar()
  246. v4 = tk.StringVar()
  247. global input1,input2,input3,input4
  248. input1 = tk.Entry(root2, textvariable=v1)
  249. input1.grid(row=0, column=1, padx=10, pady=5)
  250. input2 = tk.Entry(root2, textvariable=v2, show='*')
  251. input2.grid(row=1, column=1, padx=10, pady=5)
  252. input3 = tk.Entry(root2, textvariable=v3)
  253. input3.grid(row=2, column=1, padx=10, pady=5)
  254. input4 = tk.Entry(root2, textvariable=v4,)
  255. input4.grid(row=3, column=1, padx=10, pady=5)
  256. tk.Button(root2, text='确认', width=10, command=resiger_end).grid(row=4, column=0, sticky=tk.W, padx=10, pady=5)
  257. tk.Button(root2, text='取消', width=10, command=exit_login3).grid(row=4, column=1, sticky=tk.E, padx=10, pady=5)
  258. def frame():
  259. global root
  260. root = tk.Tk()
  261. root.title('YTU图书管理系统登录')
  262. root.geometry("500x500")
  263. #photo=tk.PhotoImage(file=BACK_PATH)
  264. #theLabel = tk.Label(root,image = photo,compound = tk.CENTER,fg = "white").pack(fill="both",expand=1)
  265. tk.Button(root, text='登入', width=70,height=9, command=auto_login).grid(row=0, column=0,)
  266. tk.Button(root, text='注册', width=70,height=9, command=resiger).grid(row=1, column=0)
  267. tk.Button(root, text='退出',width=70,height=9,command=exit_login).grid(row=2, column=0)
  268. root.mainloop()
  269. if __name__ == '__main__':
  270. frame()
文章知识点与官方知识档案匹配,可进一步学习相关知识
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/662944
推荐阅读
相关标签
  

闽ICP备14008679号