基于python的停车场管理系统(毕设)
基于python+tkinter的停车场管理系统,thinter实现gui界面管理操作。主要包括车辆信息录入,删除,查询,修改等功能。效果图:由于文件太多,全部项目请访问https://download.csdn.net/download/qq_45056668/85695201...
·
项目介绍
基于python+tkinter的停车场管理系统,thinter实现gui界面管理操作。主要包括车辆信息录入,删除,查询,修改等功能。
1.登录界面
import tkinter as tk
import tkinter.messagebox as msgbox
import os
import pickle
import threading
window = tk.Tk()
window.resizable(0, 0)
window.title("停车场信息管理系统")
# 窗口居中
ww, wh = 400, 250
sw, sh = window.winfo_screenwidth(), window.winfo_screenheight()
x, y = (sw - ww) / 2, (sh - wh) / 2
window.geometry("%dx%d+%d+%d" % (ww, wh, x, y))
# 欢迎使用
l_wlc = tk.Label(window, text="Welcome!", font=("Arial", 32))
l_wlc.pack()
# 用户名标签框
l_usr = tk.Label(window, text="用户名:")
l_usr.place(x=65, y=100)
l_key = tk.Label(window, text="密码:")
l_key.place(x=65, y=140)
# 用户名输入框
var1 = tk.StringVar()
var2 = tk.StringVar()
e_usr = tk.Entry(window, textvariable=var1)
e_key = tk.Entry(window, textvariable=var2, show="*")
e_usr.place(x=145, y=100)
e_key.place(x=145, y=140)
# 多线程实现同时打开新窗口和关闭本窗口
def tuichu():
window.quit()
def open_new():
os.system("mainWindow.py")
# 登录
def login():
t1 = threading.Thread(target=tuichu)
t1.daemon = 1
t2 = threading.Thread(target=open_new)
t2.daemon = 1
# 获得用户名字符串和密码字符串
usr = var1.get()
pwd = var2.get()
# 登录前检查:判断输入框是否为空
if usr != "":
if pwd != "":
# 将pickle内信息写入到listAll中
listAll = []
try:
with open("administrators.pickle", "rb+") as fp:
try:
while True:
temp = pickle.load(fp)
listAll.append(temp)
except EOFError:
pass
except FileNotFoundError:
with open("administrators.pickle", "wb") as fp:
pickle.dump(("admin", "admin"), fp)
else:
pass
# 检查该管理用户是否在存档中,密码是否匹配
for person in listAll:
if person[0] == usr and person[1] == pwd:
with open("record.txt", "w+") as file:
file.write("这是一个用于存储登录用户的名字的临时文件(注意:此文本由程序自动创建,不可擅自修改)\n"+usr)
t1.start()
t2.start()
break
else:
msgbox.showerror(message="用户名或者密码错误!")
else:
msgbox.showerror("⚠", "请输入密码")
else:
msgbox.showerror("⚠", "请输入用户名")
btn_login = tk.Button(window, text="登录", width=8, command=login)
btn_login.place(x=145, y=190)
# 退出
btn_exit = tk.Button(window, text="退出", width=8, command=window.quit)
btn_exit.place(x=220, y=190)
# 注册 调用注册界面
效果图:
2.注册界面
import tkinter as tk
import pickle
import tkinter.messagebox as msgbox
window = tk.Tk()
window.resizable(0, 0)
window.title("注册")
# 窗口居中
ww, wh = 400, 250
sw, sh = window.winfo_screenwidth(), window.winfo_screenheight()
x, y = (sw - ww) / 2, (sh - wh) / 2
window.geometry("%dx%d+%d+%d" % (ww, wh, x, y))
# 用户名
l_usr = tk.Label(window, text="用户名:")
l_usr.place(x=50, y=60)
# 密码
l_key = tk.Label(window, text="密码:")
l_key.place(x=50, y=90)
# 密码确认
l_cf = tk.Label(window, text="确认密码:")
l_cf.place(x=50, y=120)
# 单行文本框
var_usr = tk.StringVar()
var_key = tk.StringVar()
var_cf = tk.StringVar()
e_usr = tk.Entry(window, width=35, textvariable=var_usr)
e_key = tk.Entry(window, width=35, textvariable=var_key)
e_cf = tk.Entry(window, width=35, textvariable=var_cf)
e_usr.place(x=120, y=60)
e_key.place(x=120, y=90)
e_cf.place(x=120, y=120)
def check_or_create(yonghu, mima):
listAll = []
with open("administrators.pickle", "rb") as fp:
try:
while True:
temp = pickle.load(fp)
listAll.append(temp)
except EOFError:
pass
# 读取了空文件的操作
if len(listAll) != 0:
for person in listAll:
if person[0] == yonghu:
msgbox.showerror(message="用户已存在")
break
else:
# 写入当前用户信息
with open("administrators.pickle", "ab") as fp:
pickle.dump((yonghu, mima), fp)
msgbox.showinfo(message="恭喜,创建成功!")
# 按钮设置
def save():
# 获取输入信息
usr = var_usr.get()
key = var_key.get()
cf = var_cf.get()
# 先检查用户名输入是否为空,若为空则报错
if usr != "":
if key != "":
if cf != "":
# 先检查两次密码是否一致
if key == cf:
# 试图打开文件并读取内容,若文件不存在则新建并初始化
try:
check_or_create(usr, key)
except FileNotFoundError:
with open("administrators.pickle", "wb") as fp:
pickle.dump(("admin", "admin"), fp)
else:
pass
else:
msgbox.showerror(title="⚠", message="两次密码不一致")
else:
msgbox.showerror("⚠", "确认密码为空!")
else:
msgbox.showerror("⚠", "密码为空!")
else:
msgbox.showerror("⚠", "用户名为空!")
btn_save = tk.Button(window, text="保存", width=10, command=save)
btn_exit = tk.Button(window, text="取消", width=10, command=window.quit)
btn_save.place(x=140, y=170)
btn_exit.place(x=240, y=170)
window.mainloop()
3.添加信息
import tkinter as tk
import tkinter.messagebox as msgbox
import sqlite3
from turtle import color
def addquote(string):
"""为any加上引号"""
return "\'" + str(string) + "\'"
window = tk.Tk()
window.resizable(0, 0)
window.title("添加车辆信息")
# 窗口居中
ww, wh = 300, 300
sw, sh = window.winfo_screenwidth(), window.winfo_screenheight()
x, y = (sw - ww) / 2, (sh - wh) / 2
window.geometry("%dx%d+%d+%d" % (ww, wh, x, y))
l_Id = tk.Label(window, text="车牌号:")
l_Name = tk.Label(window, text="姓名:")
l_Color = tk.Label(window, text="颜色:")
l_Addr = tk.Label(window, text="住址:")
l_Phone = tk.Label(window, text="电话:")
# 间隔30
l_Id.place(x=10, y=20)
l_Name.place(x=10, y=50)
l_Color.place(x=10, y=80)
l_Addr.place(x=10, y=110)
l_Phone.place(x=10, y=140)
# 录入框/获得单行文本框的信息
def checkdata():
if e_Id.get() is None:
return False
try:
int(e_Id.get())
return True
except ValueError:
msgbox.showwarning(message="非法输入")
return False
# 检查字符串是否由数字组成
def check_value(string):
try:
int(string)
return True
except ValueError:
return False
var_id = tk.StringVar()
var_name = tk.StringVar()
var_color = tk.StringVar()
var_addr = tk.StringVar()
var_phone = tk.StringVar()
e_Id = tk.Entry(window, width=30, textvariable=var_id)
e_Name = tk.Entry(window, width=30, textvariable=var_name)
e_Color = tk.Entry(window, width=30, textvariable=var_color)
e_Addr = tk.Entry(window, width=30, textvariable=var_addr)
e_Phone = tk.Entry(window, width=30, textvariable=var_phone,validate="focusout", invalidcommand=checkdata)
# 间隔30
e_Id.place(x=60, y=20)
e_Name.place(x=60, y=50)
e_Color.place(x=60, y=80)
e_Addr.place(x=60, y=110)
e_Phone.place(x=60, y=140)
# 按钮
def func_save():
# 检查车牌号是否为空,为空则报错 通过entry属性实现
# todo
if e_Id.get() == "":
msgbox.showwarning(message="车牌号为空")
else:
ids, name, color, addr, phone = var_id.get(), var_name.get(), var_color.get(), var_addr.get(), var_phone.get() # 获得输入的文本内容
con = sqlite3.connect("./car_info.db") # 连接数据库
cur = con.cursor() # 创建游标对象
# 尝试写入,如果遇到重复则报错,确认是否需要修改
try:
cur.execute('insert into car values("%s","%s","%s","%s","%s")' % (ids, name, color, addr, phone))
msgbox.showinfo(message="添加成功!")
window.quit()
except sqlite3.IntegrityError:
msgbox.showerror("⚠", "车牌号重复")
res = msgbox.askyesno("⚠", "是否需要覆盖")
if res is True:
res2 = msgbox.askokcancel("⚠", "一旦确认则无法撤销,请确认")
if res2 is True:
cur.execute("update car set name=?, color=?, addr=?, phone=? where id=?", (name, color, addr, phone, ids))
# else:
# window.quit()
con.commit()
cur.close()
con.close()
btn_save = tk.Button(window, text="保存", width=10, command=func_save)
btn_exit = tk.Button(window, text="退出", width=10, command=window.quit)
btn_save.place(x=110, y=220)
btn_exit.place(x=200, y=220)
window.mainloop()
由于文件太多,全部项目请访问
https://download.csdn.net/download/qq_45056668/85695201
更多推荐
已为社区贡献2条内容
所有评论(0)