python 图书管理系统界面设计 代码
时间: 2023-09-08 17:15:10 浏览: 125
python图书管理系统
5星 · 资源好评率100%
以下是一个简单的Python图书管理系统的界面设计代码,基于Tkinter库实现,你可以根据需求自行修改和完善:
```python
import tkinter as tk
from tkinter import messagebox
class Book:
def __init__(self, title, author, isbn):
self.title = title
self.author = author
self.isbn = isbn
class Library:
def __init__(self):
self.books = []
def add_book(self, book):
self.books.append(book)
def search_book(self, keyword):
result = []
for book in self.books:
if keyword in book.title or keyword in book.author or keyword in book.isbn:
result.append(book)
return result
class App:
def __init__(self):
self.window = tk.Tk()
self.window.title("图书管理系统")
self.window.geometry("400x300")
self.library = Library()
self.title_label = tk.Label(self.window, text="图书管理系统", font=("Arial", 20))
self.title_label.pack(pady=20)
self.add_book_frame = tk.Frame(self.window)
self.add_book_frame.pack(pady=10)
self.add_book_title_label = tk.Label(self.add_book_frame, text="书名:")
self.add_book_title_label.pack(side=tk.LEFT)
self.add_book_title_entry = tk.Entry(self.add_book_frame, width=30)
self.add_book_title_entry.pack(side=tk.LEFT)
self.add_book_author_label = tk.Label(self.add_book_frame, text="作者:")
self.add_book_author_label.pack(side=tk.LEFT)
self.add_book_author_entry = tk.Entry(self.add_book_frame, width=30)
self.add_book_author_entry.pack(side=tk.LEFT)
self.add_book_isbn_label = tk.Label(self.add_book_frame, text="ISBN:")
self.add_book_isbn_label.pack(side=tk.LEFT)
self.add_book_isbn_entry = tk.Entry(self.add_book_frame, width=30)
self.add_book_isbn_entry.pack(side=tk.LEFT)
self.add_book_button = tk.Button(self.window, text="添加图书", command=self.add_book)
self.add_book_button.pack()
self.search_book_frame = tk.Frame(self.window)
self.search_book_frame.pack(pady=10)
self.search_book_label = tk.Label(self.search_book_frame, text="搜索图书:")
self.search_book_label.pack(side=tk.LEFT)
self.search_book_entry = tk.Entry(self.search_book_frame, width=30)
self.search_book_entry.pack(side=tk.LEFT)
self.search_book_button = tk.Button(self.window, text="搜索", command=self.search_book)
self.search_book_button.pack()
self.result_label = tk.Label(self.window, text="")
self.result_label.pack()
def add_book(self):
title = self.add_book_title_entry.get()
author = self.add_book_author_entry.get()
isbn = self.add_book_isbn_entry.get()
book = Book(title, author, isbn)
self.library.add_book(book)
messagebox.showinfo("成功", "添加图书成功!")
def search_book(self):
keyword = self.search_book_entry.get()
result = self.library.search_book(keyword)
if len(result) == 0:
self.result_label.config(text="没有找到相关图书!")
else:
text = ""
for book in result:
text += "书名:{},作者:{},ISBN:{}\n".format(book.title, book.author, book.isbn)
self.result_label.config(text=text)
def run(self):
self.window.mainloop()
if __name__ == '__main__':
app = App()
app.run()
```
这段代码实现了一个简单的图书管理系统,包括添加图书和搜索图书两个功能。你可以根据自己的需求进行修改和扩展。
阅读全文