You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.9 KiB

import tkinter as tk
from tkinter import messagebox, Toplevel
# 假设这是你的登录函数,现在增加成功登录后的逻辑
def login_success():
global login_window
username = entry_username.get()
password = entry_password.get()
if username == "1" and password == "1":
# 隐藏登录窗口
login_window.withdraw()
# 打开新的窗口作为主功能页面
open_main_system()
else:
messagebox.showerror("登录失败", "用户名或密码错误,请重试。")
def open_main_system():
# 主功能页面的实现
main_system_window = Toplevel(login_window)
main_system_window.title("停车场管理系统 - 主功能")
label_welcome = tk.Label(main_system_window, text="欢迎使用停车场管理系统!")
label_welcome.pack(pady=10)
class ParkingSystemApp:
def __init__(self, master):
self.master = master
master.title("停车场管理系统")
self.vehicle_listbox = tk.Listbox(master, width=50)
self.vehicle_listbox.pack(pady=10)
self.search_entry = tk.Entry(master)
self.search_entry.pack(pady=5)
tk.Button(master, text="查询车辆", command=self.search_vehicle).pack(side=tk.LEFT, padx=5)
tk.Button(master, text="录入入场", command=self.add_vehicle).pack(side=tk.LEFT, padx=5)
tk.Button(master, text="删除出场", command=self.remove_vehicle).pack(side=tk.LEFT, padx=5)
tk.Button(master, text="退出系统", command=self.quit_app).pack(side=tk.RIGHT, padx=5)
# 示例数据,实际应用中应从数据库读取
self.vehicles = ["ABC123", "XYZ789", "CDE456"]
# 初始加载车辆列表
for vehicle in self.vehicles:
self.vehicle_listbox.insert(tk.END, vehicle)
def search_vehicle(self):
query = self.search_entry.get().strip()
if query:
self.vehicle_listbox.delete(0, tk.END)
for vehicle in self.vehicles:
if query.lower() in vehicle.lower():
self.vehicle_listbox.insert(tk.END, vehicle)
def add_vehicle(self):
new_vehicle = simpledialog.askstring("录入车辆", "请输入车牌号:")
if new_vehicle and new_vehicle not in self.vehicles:
self.vehicles.append(new_vehicle)
self.vehicle_listbox.insert(tk.END, new_vehicle)
def remove_vehicle(self):
selected = self.vehicle_listbox.curselection()
if selected:
vehicle_to_remove = self.vehicle_listbox.get(selected[0])
confirm = messagebox.askyesno("确认删除", f"确定要删除车辆 {vehicle_to_remove}?")
if confirm:
self.vehicles.remove(vehicle_to_remove)
self.vehicle_listbox.delete(selected)
def quit_app(self):
self.master.destroy()
def main():
root = tk.Tk()
app = ParkingSystemApp(root)
root.mainloop()
if __name__ == "__main__":
main()
# 这里可以添加更多功能按钮和控件,如之前示例中的浏览、查询、录入、删除功能
# 注意:关闭此窗口时,可能需要同时关闭登录窗口
main_system_window.protocol("WM_DELETE_WINDOW", lambda: [main_system_window.destroy(), login_window.destroy()])
# 原始登录界面的创建
login_window = tk.Tk()
login_window.title("停车场管理系统 - 登录")
# 登录界面的元素定义...
label_username = tk.Label(login_window, text="用户名:")
label_username.pack()
entry_username = tk.Entry(login_window)
entry_username.pack()
label_password = tk.Label(login_window, text="密码:")
label_password.pack()
entry_password = tk.Entry(login_window, show="*")
entry_password.pack()
button_login = tk.Button(login_window, text="登录", command=login_success)
button_login.pack(pady=10)
login_window.mainloop()