帮我写过程序 界面设计简洁明了,易于操作,可以采用卡片式布局,每个房间的信息都包含在一个卡片中,显示房间的图片、租金、面积、地址、水、电等费用以及备注等信息; 可以设置筛选和排序功能,用户可以按照租金、面积、地址等条件进行筛选,也可以按照价格、面积等进行升降序排列
时间: 2023-05-30 17:03:03 浏览: 135
多行业多用途卡片式UI界面_应用界面UI素材.zip
以下是Python语言的实现示例:
import tkinter as tk
from tkinter import ttk
class Room:
def __init__(self, name, rent, area, address, water, electricity, remark):
self.name = name
self.rent = rent
self.area = area
self.address = address
self.water = water
self.electricity = electricity
self.remark = remark
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.rooms = []
self.create_widgets()
def create_widgets(self):
self.search_frame = tk.Frame(self.master)
self.search_frame.pack(side='top', fill='x')
self.search_label = tk.Label(self.search_frame, text='Search by: ')
self.search_label.pack(side='left')
self.search_combobox = ttk.Combobox(self.search_frame, values=['Rent', 'Area', 'Address'])
self.search_combobox.pack(side='left')
self.sort_frame = tk.Frame(self.master)
self.sort_frame.pack(side='top', fill='x')
self.sort_label = tk.Label(self.sort_frame, text='Sort by: ')
self.sort_label.pack(side='left')
self.sort_combobox = ttk.Combobox(self.sort_frame, values=['Price', 'Area'])
self.sort_combobox.pack(side='left')
self.sort_button = tk.Button(self.sort_frame, text='Sort', command=self.sort_rooms)
self.sort_button.pack(side='left')
self.add_button = tk.Button(self.master, text='Add Room', command=self.add_room)
self.add_button.pack(side='top')
self.rooms_frame = tk.Frame(self.master)
self.rooms_frame.pack(side='top', fill='both', expand=True)
def add_room(self):
name = tk.simpledialog.askstring('Add Room', 'Enter room name')
rent = tk.simpledialog.askinteger('Add Room', 'Enter rent')
area = tk.simpledialog.askinteger('Add Room', 'Enter area')
address = tk.simpledialog.askstring('Add Room', 'Enter address')
water = tk.simpledialog.askinteger('Add Room', 'Enter water fee')
electricity = tk.simpledialog.askinteger('Add Room', 'Enter electricity fee')
remark = tk.simpledialog.askstring('Add Room', 'Enter remark')
room = Room(name, rent, area, address, water, electricity, remark)
self.rooms.append(room)
self.update_rooms()
def update_rooms(self):
for child in self.rooms_frame.winfo_children():
child.destroy()
for room in self.rooms:
card = tk.Frame(self.rooms_frame, borderwidth=2, relief='groove')
card.pack(side='top', fill='x', padx=10, pady=5)
name_label = tk.Label(card, text=room.name)
name_label.pack(side='left')
rent_label = tk.Label(card, text='Rent: ' + str(room.rent))
rent_label.pack(side='left', padx=10)
area_label = tk.Label(card, text='Area: ' + str(room.area))
area_label.pack(side='left', padx=10)
address_label = tk.Label(card, text='Address: ' + room.address)
address_label.pack(side='left', padx=10)
water_label = tk.Label(card, text='Water: ' + str(room.water))
water_label.pack(side='left', padx=10)
electricity_label = tk.Label(card, text='Electricity: ' + str(room.electricity))
electricity_label.pack(side='left', padx=10)
remark_label = tk.Label(card, text='Remark: ' + room.remark)
remark_label.pack(side='left', padx=10)
def sort_rooms(self):
key = self.sort_combobox.get()
if key == 'Price':
self.rooms.sort(key=lambda x: x.rent)
elif key == 'Area':
self.rooms.sort(key=lambda x: x.area)
self.update_rooms()
root = tk.Tk()
app = Application(master=root)
app.mainloop()
阅读全文