Python 与SQL sever数据库 图形化智能停车场管理系统

    这个是我的一次课程设计,写了236行代码,都是最简单的函数和图形化界面。特别简单。 首先你应该确保你的SQL数据库可以在Pycham中连接成功。不会SQL连接的的可以去其他博客写看一看。 在Pycham中需要安装 Tkinter   win32com.client 第三方库。
序言 界面截图展示 数据库展示 代码
    序言:下面的代码是模块化的,拼起来就是一个完整的小系统。如果你不想自己拼或者拼起来有问题,可以私聊我。 我其实也是个小菜。
停车界面
def Menu1():
    root = tkinter.Tk(className='界面')
    root.title='界面'
    label = tkinter.Label(root, text="Hello Hello欢迎进入智能停车收费停车场", bg='yellow')
    root.geometry('300x300+260+160')
    label.pack()
    def click1():
        park()
    def click2():
        find()
    def click3():
        dispcust()
    def click5():
        root.destroy()
        ased()
    def click4():
        dis()
    def click6():
        sum()
    def click7():
        exit(0)
    button1 = tkinter.Button(root, text='1)停车', bg='blue', width=20, command=click1)
    button1.pack()
    button2 = tkinter.Button(root, text='2)查询', bg='blue', width=20, command=click2)
    button2.pack()
    button3 = tkinter.Button(root, text='3)显示', bg='blue', width=20, command=click3)
    button3.pack()
    button4 = tkinter.Button(root, text='4)帮助', bg='blue', width=20, command=click4)
    button4.pack()
    button5 = tkinter.Button(root, text='5)取车', bg='blue', width=20, command=click5)
    button5.pack()
    button6 = tkinter.Button(root, text='6)统计', bg='blue', width=20, command=click6)
    button6.pack()
    button7 = tkinter.Button(root, text='7)退出', bg='blue', width=20, command=click7)
    button7.pack()
    root.mainloop()
def park():   #操作1   添加用户
    rt1 = tkinter.Tk(className='测试')
    rt1.geometry('380x200+650+150')
    t1 =  Entry(rt1,show=None )
    t1.place(x=120, y=10)
    t2 = Label(rt1, text='车号:')
    t2.place(x=60, y=10)
    t3 =  Entry(rt1, show=None)
    t3.place(x=120, y=60)
    t4 = Label(rt1, text='车主:')
    t4.place(x=60, y=60)
    t5 = Label(rt1, text='颜色:')
    t5.place(x=60, y=100)
    t6 = Entry(rt1, show=None)
    t6.place(x=120, y=100)
    def queding():
        v1 = t1.get()
        v2 = t3.get()
        v3 = t6.get()
        if v1=='' or v2=='' or v3=='':
            tkinter.messagebox.showinfo(title='添加失败',message="输入无效!!!")
        else:
            cn = win32com.client.Dispatch('ADODB.Connection')
            cnstr = 'Provider = SQLOLEDB.1;Integrated Security = SSPI;Data Source=DESKTOP-KHP9P0M'
            cn.Open(cnstr, 'sa', 'sa')
            cn.DefaultDatabase = 'sst'
            cn.Execute("USE sst")
            cn.Execute("INSERT INTO sst1 VALUES('%s','%s','%s')" % (v1, v2, v3))
            tkinter.messagebox.showinfo(title='添加成功', message="%s用户停车成功!" % v1)
            rt1.destroy()
    def quxiao():
        rt1.destroy()
    bt1 = Button(rt1, text='确认', width=10, height=1, command=queding)
    bt1.place(x=80,y=140)
    bt2 = Button(rt1, text='取消', width=10, height=1,command=quxiao)
    bt2.place(x=160, y=140)
    rt1.mainloop()

def find():            #查询函数
    rt1 = tkinter.Tk(className='查询界面')
    rt1.geometry('380x240+580+250')
    lb=Label()
    t2 = Label(rt1, text='车号:')
    t2.place(x=60, y=10)
    t1 = Entry(rt1, show=None)
    t1.place(x=100, y=10)
    def queding1():
        global manfra
        tno = t1.get()
        if tno=='':
            tkinter.messagebox.showinfo(title='查询成功', message="请重新输入" )
        else:
            cn = win32com.client.Dispatch('ADODB.Connection')
            cnstr = 'Provider = SQLOLEDB.1;Integrated Security = SSPI;Data Source=DESKTOP-KHP9P0M'
            cn.Open(cnstr, 'sa', 'sa')
            cn.DefaultDatabase = 'sst'
            cn.Execute("USE sst")
            rs = win32com.client.Dispatch('ADODB.RecordSet')
            rs.Open('sst1', cn)
            i=1
            if not rs.EOF:
                while not rs.EOF:
                    if (rs.Fields(0).Value).strip() == tno:
                        s1 = rs.Fields(0).Value
                        s2 = rs.Fields(1).Value
                        s3 = rs.Fields(2).Value
                        t3 = Label(rt1, text='车号:')
                        t3.place(x=60, y=120)
                        t4 = Entry(rt1, show=None)
                        t4.insert(INSERT, s1)
                        t4.place(x=100, y=120)
                        t5 = Label(rt1, text='车主:')
                        t5.place(x=60, y=140)
                        t6 = Entry(rt1, show=None)
                        t6.insert(INSERT, s2)
                        t6.place(x=100, y=140)
                        t7 = Label(rt1, text='颜色:')
                        t7.place(x=60, y=160)
                        t8 = Entry(rt1, show=None)
                        t8.insert(INSERT, s3)
                        i=2
                        t8.place(x=100, y=160)
                        t9 = Label(rt1, text='查询结果:', font=('微软雅黑', 15, 'bold'))
                        t9.place(x=60, y=80)
                    rs.MoveNext()
            else:
                tkinter.messagebox.showinfo(title='查询失败', message="该车库无%s车号信息"%tno)
        if i==1:
                tkinter.messagebox.showinfo(title='查询失败', message="该车库无%s车号信息"%tno)
    def ass():
        rt1.destroy()
    bt1 = Button(rt1, text='确认', width=10, height=1, command=queding1)
    bt1.place(x=80, y=200)
    bt2 = Button(rt1, text='取消', width=10, height=1, command=ass)
    bt2.place(x=200, y=200)
    rt1.mainloop()

def dispcust():  #显示客户
    cn = win32com.client.Dispatch('ADODB.Connection')
    cnstr = 'Provider = SQLOLEDB.1;Integrated Security = SSPI;Data Source=DESKTOP-KHP9P0M'
    cn.Open(cnstr, 'sa', 'sa')
    cn.DefaultDatabase = 'sst'
    cn.Execute("USE sst")
    rt8=Tk(className='显示客户')
    tr2 = Label(rt8, text='车号信息:',font=('微软雅黑', 15, 'bold'))
    tr2.place(x=10, y=10)
    rt8.geometry('300x300+600+200')
    text1=Text(rt8,width=30,height=15)
    text1.place(x=10,y=80)
    tr3 = Label(rt8, text='车号')
    tr3.place(x=10, y=50)
    tr4 = Label(rt8, text='车主')
    tr4.place(x=86, y=50)
    tr5 = Label(rt8, text='颜色')
    tr5.place(x=150, y=50)
    rs=win32com.client.Dispatch('ADODB.RecordSet')
    rs.Open('sst1',cn)
    if not rs.EOF:
        #text1.insert(INSERT,'车号    \t车主    \t颜色 ')
        while not rs.EOF:
            text1.insert(INSERT,rs.Fields(0).Value)
            text1.insert(INSERT,rs.Fields(1).Value)
            text1.insert(INSERT,rs.Fields(2).Value)
            rs.MoveNext()
    else:
        tkinter.messagebox.showinfo(title='车库', message="车库空空如也!!!!")

    rt8.mainloop()

def ased():
    rt6 = Tk()
    rt6.geometry('600x400+400+200')
    rt6.title('出车界面')
    rt6.iconbitmap('pro.ico')
    idat = PhotoImage(file='Prou.gif', width=850, height=450)
    lab1 = Label(image=idat)
    lab1.place(x=0, y=0)
    def as1():
        v6 = t3.get()
        cn = win32com.client.Dispatch('ADODB.Connection')
        cnstr = 'Provider = SQLOLEDB.1;Integrated Security = SSPI;Data Source=DESKTOP-KHP9P0M'
        cn.Open(cnstr, 'sa', 'sa')
        cn.DefaultDatabase = 'sst'
        cn.Execute("USE sst")
        cn.Execute("delete from sst1 where cno=%s" % v6)
        tkinter.messagebox.showinfo(title='出车', message="%s用户出车成功!\n 您需要支付3元的停车费" % v6)

    def as2():
        rt6.destroy()
        Menu1()
    def as3():
        def as4():
            rt7.destroy()
        rt7 = Tk('5x5+200+200')
        rt7.title('支付界面')
        bt1 = Button(rt7, text='完成支付', width=10, height=1,command=as4)
        bt1.place(x=10, y=20)
        lab3 = Label(text='请扫描下方二维码完成支付')
        lab3.pack()
        idat1 = PhotoImage(file='Prou1.png', width=420, height=318)
        lab3 = Label(image=idat1)
        lab3.place(x=0, y=0)
        rt7.mainloop()
    bt1 = Button(rt6, text='确认', width=10, height=1, command=as1)
    bt1.place(x=430, y=200)
    bt2 = Button(rt6, text='取消', width=10, height=1, command=as2)
    bt2.place(x=510, y=200)
    bt3 = Button(rt6, text='扫码支付', width=20, height=1, command=as3)
    bt3.place(x=430, y=260)
    t2 = Label(rt6, text='请输入您的车号:')
    t2.place(x=430, y=120)
    t2 = Label(rt6, text='车号:')
    t2.place(x=430, y=160)
    t3 = Entry(rt6, show=None,width=15)
    t3.place(x=460, y=160)
    label = Label(rt6, text="期待您的下次光临!!!!", bg='blue', width=85, height=3)
    label.place(x=0, y=350)
    manfra = LabelFrame()
    manfra.pack()
    rt6.mainloop()

def sum():
    cn = win32com.client.Dispatch('ADODB.Connection')
    cnstr = 'Provider = SQLOLEDB.1;Integrated Security = SSPI;Data Source=DESKTOP-KHP9P0M'
    cn.Open(cnstr, 'sa', 'sa')
    cn.DefaultDatabase = 'sst'
    cn.Execute("USE sst")
    rs = win32com.client.Dispatch('ADODB.RecordSet')
    rs.Open('sst1', cn)
    s=0
    while not rs.EOF:
        s=s+1
        rs.MoveNext()
    rs.Close()
    tkinter.messagebox.showinfo(title='统计信息', message="停车车场共有%d辆车!" %s)

def dis():     #帮助信息
    tkinter.messagebox.showinfo(title='帮助',message='这么简单的界面要什么帮助!\n是不是不想掏钱!\n 想跑!!!\n门都没有')

数据库展示,这里只用了数据库的一张表,比较简单。如果想要多表操作,你可以修改上面的SQL语句,然后在调用模块函数。

栏目