代码 基于gui的图书管理系统
时间: 2023-09-15 08:22:30 浏览: 95
好的,以下是一个基于 GUI 的图书管理系统的 Python 代码示例,供参考:
```python
from tkinter import *
from tkinter import messagebox
# 创建图书管理系统主界面
root = Tk()
root.title("图书管理系统")
root.geometry('500x300')
# 创建标签
label_title = Label(root, text="欢迎来到图书管理系统", font=("Arial", 20))
label_title.pack(pady=10)
# 创建输入框和标签
label_bookname = Label(root, text="书名:")
label_bookname.place(x=50, y=80)
entry_bookname = Entry(root, width=20)
entry_bookname.place(x=110, y=80)
label_author = Label(root, text="作者:")
label_author.place(x=50, y=120)
entry_author = Entry(root, width=20)
entry_author.place(x=110, y=120)
label_publisher = Label(root, text="出版社:")
label_publisher.place(x=50, y=160)
entry_publisher = Entry(root, width=20)
entry_publisher.place(x=110, y=160)
# 定义添加图书函数
def add_book():
bookname = entry_bookname.get()
author = entry_author.get()
publisher = entry_publisher.get()
if bookname == "" or author == "" or publisher == "":
messagebox.showerror("错误", "请输入完整信息")
else:
with open("booklist.txt", "a") as f:
f.write(f"{bookname},{author},{publisher}\n")
messagebox.showinfo("成功", "添加图书成功")
# 创建添加图书按钮
btn_add = Button(root, text="添加图书", width=10, command=add_book)
btn_add.place(x=250, y=200)
root.mainloop()
```
这个示例代码实现了一个简单的图书管理系统,包含了添加图书的功能。您可以根据自己的需求修改和完善代码。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)