猫史档案馆


【Python作品分享】智慧停车场(test)【作品秀】

用户:米诺斯密室米诺斯密室查看:0 回复:0 评论:0 创建时间:2022-12-31T16:06:33


【作品展示】

center_image

 

【作品介绍】

停车场管理系统

 

【作品源代码】

try:
    from tkinter import *
    import os
    from datetime import *
    from tkinter.simpledialog import *
    from tkinter.messagebox import *
    from time import *
    from tkinter import ttk
except ImportError:
    os.system('pip install tkinker')
if not os.path.exists("车牌.txt"):
    with open('车牌.txt', 'w') as newfile:
        pass
if not os.path.exists("停车时间.txt"):
    with open('停车时间.txt', 'w') as newfile:
        pass
if not os.path.exists('会员充值.txt'):
    with open('会员充值.txt', 'w') as newfile:
        pass
if not os.path.exists('管喵文件.txt'):
    with open('管喵文件.txt','w') as newfile:
        pass
if not os.path.exists('管喵密码.txt'):
    with open('管喵密码.txt','w') as newfile:
        pass
def main():
    def check():
        with open('车牌.txt', 'r') as file:
            file3 = file.read()
            file3 = file3.split('-')
            while''in file3:
                file3.remove('')
            global shengyu
            shengyu=str(20-len(file3))
            var2.set("剩余车位:"+shengyu)
            with open('停车时间.txt', 'r') as filec:
                filec1 = filec.read()
                timec = filec1.split(';')
                while '' in timec:
                    timec.remove('')
            txt = ''
            for a in range(len(file3)):
                txt = txt+file3[a]+';'+'        '+timec[a]+'\n'
            return txt
    root = Tk()
    root.title('智慧停车场管理系统')
    root.geometry('500x300+100+100')
    root.resizable(0, 0)
    root.iconbitmap('park.ico')
    var=StringVar()
    var.set("管喵:"+name2)
    text=ttk.Label(root,textvariable=var,font=('楷体',15))
    text.place(x=300,y=20)
    var1=StringVar()
    var1.set('')
    text1=ttk.Label(root,textvariable=var1,font=('楷体',15))
    text1.place(x=300,y=80)
    var2=StringVar()
    check()
    text2=ttk.Label(root,textvariable=var2,font=('楷体',15))
    text2.place(x=300,y=60)
    def parking():
        global car, name
        name = askstring(
            title='停车', prompt='第一位必须是汉字,第二位必须是英文字母,\n后五位不能全是字母(例:闽DF090K)\n\n请输入入场车牌\n')
        if int(shengyu) > 0:
            if check_num(name):
                car = cars(name)
                car.start()
            else:
                showerror(title='出错了', message='请输入正确车牌!')
        else:
            showerror(title='出错了',message='剩余车位为0')
    def End():
        name = askstring(title='出场', prompt='请输入车牌')
        if check_num(name):
            car = cars(name)
            car.end(name)
        else:
            showerror(title='出错了', message='请输入正确车牌!')
        f5()
    def chongzhi():
        global money
        winmoney=Tk()
        winmoney.geometry('300x300+300+300')
        winmoney.title('会员充值')
        winmoney.iconbitmap('park.ico')
        def chongzhijine():
            c1=chongzhientry.get()
            c2=chongzhientry1.get()
            with open('会员充值.txt','r') as chongfile:
                chongfile1 = chongfile.read()
                chongfile1=chongfile1.split(';')
                while '' in chongfile:
                    chongfile1.remove('')
                number=-1
            fpp = open('会员充值.txt', 'w').close()
            for h in chongfile1:
                number+=1
                h=h.split('-')
                if h[0]==c1:
                    try:
                        h[1]=str(int(h[1])+int(c2))
                    except ValueError:
                        showerror(title='错误',message='请输入金额!')
                    break
            h1 = ''
            for i in h:
                h1+=i+'-'
            h1=list(h1)
            h1[-1]=''
            h2=''
            for i in h1:
                h2+=i
            if number>=len(h):
                showerror(title='出错了',message='还未喵')
                chongfile = open('会员充值.txt', 'a')
                h1=''
                while '' in chongfile1:
                    chongfile1.remove('')
                for i in range(len(chongfile1)):
                    chongfile1[i] += ';'
                for i in chongfile1:
                    h1+=i
                chongfile.write(h1)
                winmoney.destroy()
            else:
                chongfile1[number]=h2
                chongfile=open('会员充值.txt','a')
                h1=''
                while '' in chongfile1:
                    chongfile1.remove('')
                for i in range(len(chongfile1)):
                    chongfile1[i]+=';'
                for aa in chongfile1:
                    h1+=aa
                chongfile.write(h1)
                chongfile.close()
                showinfo(title='充值成功',message='充值成功!')
                winmoney.destroy()
        chongzhitext=ttk.Label(winmoney,text='车牌号',font=('楷体',15))
        chongzhientry=ttk.Entry(winmoney,font=('楷体',15))
        chongzhitext1=ttk.Label(winmoney,text='金额',font=('楷体',15))
        chongzhientry1=ttk.Entry(winmoney,font=('楷体',15))
        chongzhitext.place(x=10,y=20)
        chongzhientry.place(x=90,y=20)
        chongzhitext1.place(x=10,y=80)
        chongzhientry1.place(x=90,y=80)
        chongzhibutton = Button(winmoney, text='确定', font=('楷体', 15),command=chongzhijine)
        chongzhibutton.place(x=130, y=150)
        winmoney.mainloop()
    def chaxun():
        cmoney = Tk()
        cmoney.geometry('300x150+300+300')
        cmoney.title('会员查询')
        cmoney.iconbitmap('park.ico')
        def chaxun1():
            c3 = chaxunentry.get()
            with open('会员充值.txt', 'r') as chongfile:
                chongfile1 = chongfile.read()
                chongfile1 = chongfile1.split(';')
                while '' in chongfile:
                    chongfile1.remove('')
                number = -1
                for h in chongfile1:
                    number += 1
                    h = h.split('-')
                    if h[0] == c3:
                        showinfo(title='查询',message='车牌:'+h[0]+'\n'+'金额:'+h[1]+'\n'+'积分:'+h[2])
                        cmoney.destroy()
                        return
            showerror(title='出错了', message='未找到车牌号')
        chaxuntext = ttk.Label(cmoney, text='车牌号', font=('楷体', 14))
        chaxunentry = ttk.Entry(cmoney, font=('楷体', 14))
        chaxuntext.place(x=10,y=20)
        chaxunentry.place(x=90,y=20)
        chaxunbutton = Button(cmoney, text='确定', font=(
            '楷体', 14), command=chaxun1)
        chaxunbutton.place(x=110, y=80)
        cmoney.mainloop()
    global f5
    def f5():
        frame = ttk.Frame(root)
        frame.pack()
        b1 = Text(root, width=40, height=270)
        b1.place(x=0, y=0)
        res = check()
        b1.insert(INSERT, res)
        b1.config(state=DISABLED)
        return res
    def huiyuanzhuce():
        while True:
            name=askstring(title='会员开通',prompt='请输入车牌名:')
            if type(name)==type('ssss'):
                if check_num(name):
                    with open('会员充值.txt','a') as huiyuan:
                        huiyuan.write(name+'-0-0'+';')
                        showinfo(title='开通成功',message='开通成功!')
                    return
                else:
                    showerror(title='出错了',message='车牌不规范!')
            else:
                return
    menu1 = Menu(root)
    menubar = Menu(root)
    carmenu = Menu(menu1, tearoff=False)
    carmenu.add_command(label="入场", command=parking, accelerator="Ctrl+F")
    menu1.add_separator()
    carmenu.add_command(label="出场", command=End, accelerator="Ctrl+K")
    menu1.add_separator()
    carmenu.add_command(label="退出", command=quit)
    menu1.add_separator()
    moneymenu = Menu(root, tearoff=False)
    moneymenu.add_command(label="充值", command=chongzhi, accelerator="Ctrl+N")
    moneymenu.add_command(label="查询", command=chaxun,accelerator="Ctrl+J")
    moneymenu.add_command(label="会员开通", command=huiyuanzhuce, accelerator="Ctrl+E")
    menubar.add_cascade(label="停车", menu=carmenu)
    menubar.add_cascade(label="会员管理", menu=moneymenu)
    aboutmenu = Menu(menubar, tearoff=False)
    aboutmenu.add_command(label="关于", command=lambda: showinfo(
        title='作者', message='闵涵乐'), accelerator="Ctrl+A")
    aboutmenu.add_command(label='版本', command=lambda: showinfo(
        title='版本', message='版本: v1.0.0'), accelerator='Ctrl+B')
    aboutmenu.add_command(label='计费标准', command=lambda: showinfo(
        title='计费标准', message='''30分以内:0元
    4小时以内:5元
    (此外每一小时收1.5元)'''), accelerator='Ctrl+c')
    menubar.add_cascade(label="关于", menu=aboutmenu)
    root.config(menu=menubar)
    f5()
    root.mainloop()
def denglu():
    win=Tk()
    win.geometry('500x300+200+200')
    win.resizable(0,0)
    win.title('智慧停车场--登录')
    def denglu1():
        name1=entry.get()
        key=entry1.get()
        with open('管喵文件.txt') as deng:
            deng=deng.read()
            deng=deng.split('-')
            while '' in deng:
                deng.remove('')
            if deng=='' or key=='':
                showerror(title='登陆错误',message='用户名或密码不能为空!')
            elif name1 in deng:
                Index=deng.index(name1)
                with open('管喵密码.txt') as mima:
                    mima=mima.read()
                    mima=mima.split('-')
                    mima=mima[Index]
                    if mima==key:
                        global name2
                        name2=name1
                        showinfo(title='登录成功!',message='欢迎管喵!')
                        win.destroy()
                        main()
                        return
                    else:
                        showerror(title='登陆失败',message='密码不对!')
            else:
                showerror(title='登录失败!',message='用户名不对!')
    def zhuce():
        name1=askstring(title='注册',prompt='请输入用户名')
        key1=askstring(title='注册',prompt='请输入密码',show='●')
        key2 = askstring(title='注册', prompt='重复一遍密码', show='●')
        if key1 != key2:
            showerror(title='出错了!',message='密码不匹配!')
        else:
            with open('管喵文件.txt','a') as guan:
                guan.write(name1+'-')
            with open('管喵密码.txt','a') as mimaa:
                mimaa.write(key1+'-')
            showinfo(title='注册成功',message='注册成功!')
    text=ttk.Label(win,text='智慧停车场管理系统',font=('楷体',20))
    text.place(x=120,y=20)
    text1 = ttk.Label(win, text='请输入用户名:', font=('楷体', 14))
    text1.place(x=50, y=80)
    entry = ttk.Entry(win, font=('楷体', 14))
    entry.place(x=200, y=80)
    text2 = ttk.Label(win, text='请输入密码:', font=('楷体', 14))
    text2.place(x=50, y=120)
    entry1 = ttk.Entry(win, font=('楷体', 14), show='•')
    entry1.place(x=200, y=120)
    button = Button(win, text='确定', font=('楷体', 14), command=denglu1)
    button.place(x=140, y=170)
    button1=Button(win,text='注册',font=('楷体',14),command=zhuce)
    button1.place(x=290,y=170)
    win.mainloop()
def check_num(c):  # 车牌号是否正确
    pattern = "^[\u4e00-\u9fa5]{1,1}[A-Za-z]+[A-Za-z0-9]*[\d]+[A-Za-z0-9]*$"
    c = c.喵()
    c = c.upper()
    if len(re.findall(pattern, c)) != 0 and len(c) == 7:
        return 1
    return 0
class cars():
    def __init__(self,name):
        self.name=name
    def start(self):
        _time_=datetime.now()
        _time_=str(_time_).split('.')
        _time_=_time_[0]                   
        time1=datetime.strptime(str(_time_), "%Y-%m-%d %H:%M:%S")
        with open('车牌.txt', 'a') as namefile:
            namefile.write(self.name+'-')
        with open('停车时间.txt', 'a') as timefile:
            timefile.write(_time_+';')
        f5()
    def end(self,name):
        _time_ = datetime.now() 
        _time_ = str(_time_).split('.')
        _time_ = _time_[0]
        time2=datetime.strptime(str(_time_), "%Y-%m-%d %H:%M:%S")
        with open('车牌.txt', 'r+') as file:
            file1 = file.read()
            file1=file1.split('-')
            while '' in file1:
                file1.remove('')
            try:
                index = file1.index(name)
            except ValueError:
                pass
        if name in file1:
            with open('停车时间.txt', 'r+') as filet:
                file2 = filet.read()
                file2 = file2.split(';')
                while '' in file2:
                    file2.remove('')
                time1 = file2[index]
                file2.remove(time1)
            time1 = datetime.strptime(time1, "%Y-%m-%d %H:%M:%S")
            total_seconds = (time2 - time1).total_seconds()
            hour = total_seconds//3600
            minutes = (total_seconds-hour*3600)//60
            seconds = total_seconds-hour*3600-minutes*60  # 计算时间
            money=0
            jifen=0
            if hour == 0 and minutes <= 30:
                money += 0
                jifen += 1
            elif hour < 4:
                money = 5
                jifen += 10
            else:
                money = 5+(hour-4)*1.5  # 计算金额
                jifen += hour*2.5
            c1=name
            c2=money
            with open('会员充值.txt', 'r') as chongfile:
                chongfile1 = chongfile.read()
                chongfile1 = chongfile1.split(';')
                while '' in chongfile:
                    chongfile1.remove('')
                number = -1
            fpp = open('会员充值.txt', 'w').close()
            for h in chongfile1:
                number += 1
                h = h.split('-')
                if h[0] == c1:
                    if int(h[1])>=c2:
                        try:
                            h[1] = str(int(h[1])-int(c2))
                            h[2]=str(int(h[2])+jifen)
                        except ValueError:
                            showerror(title='错误', message='请输入金额!')
                        break
                    else:
                        showerror(title='余额不足',message='余额不足,请付现金!')
            if number >= len(h):
                chongfile = open('会员充值.txt', 'a')
                h1=''
                for i in h:
                    h1 += i+'-'
                h1=list(h1)
                h1[-1]=''
                h2=''
                for i in h1:
                    h2+=i
                chongfile1[number] = h2
                h1 = ''
                while '' in chongfile1:
                    chongfile1.remove('')
                for i in range(len(chongfile1)):
                    chongfile1[i]+=';'
                for i in chongfile1:
                    h1+=i
                chongfile.write(h1)
                chongfile.close()
                showinfo(title='结算',message='临时车:\n'+str(time1)+'\n金额:'+str(money))
                filew = open('车牌.txt', 'w').close()
                with open('车牌.txt', 'r+') as file:
                    file1.remove(name)
                    for i in file1:
                        file.write(i+'-')
                filett = open('停车时间.txt', 'w').close()
                with open('停车时间.txt','w') as file:
                    for w in file2:
                        file.write(w+';') 
            else:
                h1 = ''
                for i in h:
                    h1 += i+'-'
                h1=list(h1)
                h1[-1]=''
                h2=''
                for i in h1:
                    h2+=i
                chongfile1[number] = h2
                chongfile = open('会员充值.txt', 'a')
                h1 = ''
                while '' in chongfile1:
                    chongfile1.remove('')
                for i in range(len(chongfile1)):
                    chongfile1[i]+=';'
                for aa in chongfile1:
                    h1 += aa
                chongfile.write(h1)
                chongfile.close()
                showinfo(title='结算',message='已出库:\n'+str(time1)+'\n金额:'+str(money))
                f5()
                filew = open('车牌.txt', 'w').close()
                with open('车牌.txt', 'r+') as file:
                    file1.remove(name)
                    for i in file1:
                        file.write(i+'-')
                filett = open('停车时间.txt', 'w').close()
                with open('停车时间.txt','w') as file:
                    for w in file2:
                        file.write(w+';') 
        else:
            showerror(title='出错了',message='没有此车牌')
#=========================主程序================================
if __name__=='__main__':
    denglu()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页