**科技大学 创新指导与实践3 python食堂捎带系统

用到wxpython库,下载方法自行搜索

管理员账号密码都admin,管理员系统没写入GUI,写死了两个测试账号,账号密码都是111和222

本代码仅供学习参考,作者是大二学生,不喜勿喷

import wx
import os

# backup.txt
fdInfo = []
menu2 = []
menu3 = []
menu4 = []
menu5 = []
menu6 = []

num = '0'

# 读取菜单
def InMenu2():
    global menu2
    f = open('menu2.txt')
    content = f.read()
    menu2 = eval(content)
    f.close()


def InMenu3():
    global menu3
    f = open('menu3.txt')
    content = f.read()
    menu3 = eval(content)
    f.close()


def InMenu4():
    global menu4
    f = open('menu4.txt')
    content = f.read()
    menu4 = eval(content)
    f.close()

def InMenu5():
    global menu5
    f = open('menu5.txt')
    content = f.read()
    menu5 = eval(content)
    f.close()

def InMenu6():
    global menu6
    f = open('menu6.txt')
    content = f.read()
    menu6 = eval(content)
    f.close()

# 登陆界面
class Load(wx.Frame):
    def __init__(self, p, t):
        wx.Frame.__init__(self, id=-1, parent=p, title=t, size=(260, 240))
        # 该panel的父亲就是该窗口, id=-1就表示任意ID
        panel = wx.Panel(self, -1)
        self.menu1 = wx.StaticText(panel, -1, "账号:", pos=(30, 60))
        self.menu2 = wx.StaticText(panel, -1, "密码:", pos=(30, 100))

        self.text1 = wx.TextCtrl(panel, -1, pos=(80, 60), size=(150, -1))
        self.text2 = wx.TextCtrl(panel, -1, pos=(80, 100), size=(150, -1), style=wx.TE_PASSWORD)

        self.button1 = wx.Button(panel, -1, "登陆", pos=(30, 150), size=(200, -1))
        self.Bind(wx.EVT_BUTTON, self.LoadClick, self.button1)

    def LoadClick(self, event):
        global num
        x1 = self.text1.GetValue()  # 读取输入
        x2 = self.text2.GetValue()  # 读取输入
        # ShowMainFrame()
        if x1 == "admin" and x2 == "admin":
            main()
        elif x1 == "111" and x2 == "111":
            num = '111'
            ShowMainFrame()
        elif x1 == "222" and x2 == "222":
            num = '222'
            ShowMainFrame()

        else:
            print("账号密码错误!")


def read():
    InMenu2()
    InMenu3()
    InMenu4()
    InMenu5()
    InMenu6()
    recoverData()


def ShowMainFrame():
    read()
    frame2 = ChoiceFrame(None, "食堂捎带系统 v1.0")
    frame2.Show(True)  # 显示该窗口


class ChoiceFrame(wx.Frame):
    def __init__(self, p, t):
        wx.Frame.__init__(self, id=-1, parent=p, title=t, size=(260, 240))
        # id=-1表示任意ID
        panel = wx.Panel(self, -1)
        self.button01 = wx.Button(panel, -1, "下单", pos=(70, 30), size=(100, 40))
        self.Bind(wx.EVT_BUTTON, self.ck1, self.button01)
        self.button02 = wx.Button(panel, -1, "接单", pos=(70, 80), size=(100, 40))
        self.Bind(wx.EVT_BUTTON, self.ck2, self.button02)
        self.button03 = wx.Button(panel, -1, "记录", pos=(70, 130), size=(100, 40))
        self.Bind(wx.EVT_BUTTON, self.ck3, self.button03)


    def ck1(self, event):
        frame3 = PlaceOrder(None, "下单")
        frame3.Show(True)  # 显示该窗口
        read()

    def ck2(self, event):
        frame4 = TakeOrder(None, "接单")
        frame4.Show(True)  # 显示该窗口
        read()

    def ck3(self, event):
        frame5 = DetailFrame(None, "记录")
        frame5.Show(True)  # 显示该窗口
        read()


class PlaceOrder(wx.Frame):
    def __init__(self, p, t):
        wx.Frame.__init__(self, id=-1, parent=p, title=t, size=(500, 600))
        # id=-1表示任意ID
        panel = wx.Panel(self, -1)

        # 文本框
        self.text1 = wx.TextCtrl(panel, -1, pos=(70, 410), size=(180, -1))
        self.text2 = wx.TextCtrl(panel, -1, pos=(70, 440), size=(180, -1))
        self.text3 = wx.TextCtrl(panel, -1, pos=(70, 470), size=(180, -1))

        self.menu1 = wx.StaticText(panel, -1, "菜单:", pos=(30, 25))
        self.menu2 = wx.StaticText(panel, -1, "先输入编号、地址、电话,再点击下单", pos=(30, 380))
        self.menu3 = wx.StaticText(panel, -1, "编号:", pos=(30, 410))
        self.menu4 = wx.StaticText(panel, -1, "电话:", pos=(30, 440))
        self.menu5 = wx.StaticText(panel, -1, "地址:", pos=(30, 470))

        # 菜单列表
        self.list123 = wx.ListBox(panel, -1, choices=menu2, style=wx.LB_SINGLE, pos=(30, 50), size=(430, 320))

        self.button1 = wx.Button(panel, -1, "下单", pos=(30, 500), size=(220, 40))
        # self.button1.SetFont(font1)
        # 绑定事件,就是指定的button被单击后调用onClick()成员函数
        self.Bind(wx.EVT_BUTTON, self.xiadan, self.button1)




    def xiadan(self, event):
        global num
        numb = self.text1.GetValue()  # 读取输入 编号
        tel = self.text2.GetValue()  # 读取输入 电话
        add = self.text3.GetValue()  # 读取输入 地址

        neww = {
     }
        neww['num'] = num
        neww['phone'] = tel
        neww['address'] = add

        i = 1
        for tempInfo in fdInfo:
            if i == int(numb):
                neww['window'] = tempInfo['window']
                neww['name'] = tempInfo['name']
                neww['price'] = tempInfo['price']
            i += 1
        menu3.append(neww)
        f = open('menu3.txt', 'w')
        f.write(str(menu3))
        f.close()

        writeMenu4()

        read()

        frame01 = PlaceOrderOK(None, "提示")
        frame01.Show(True)

        self.Close()






def writeMenu4():
    if os.path.exists('menu4.txt'):
        os.remove('menu4.txt')

    menu4 = []
    title = '编号\t\t用户\t\t窗口\t\t名称\t\t\t价格\t\t电话                  地址\t\t'
    menu4.append(title)
    j = 1
    for tempInfo in menu3:
        new = str(j) + '\t\t' + tempInfo['num'] + '\t\t' + tempInfo['window'] + '\t\t' + tempInfo['name'] + '\t\t' + tempInfo['price'] + '\t\t' + tempInfo['phone'] + '   ' + tempInfo['address'] + '\t\t'
        j += 1
        menu4.append(new)

    f = open('menu4.txt', 'w')
    f.write(str(menu4))
    f.close()


class PlaceOrderOK(wx.Frame):
    def __init__(self, p, t):
        wx.Frame.__init__(self, id=-1, parent=p, title=t, size=(200, 120))
        # id=-1表示任意ID
        panel = wx.Panel(self, -1)

        self.txt = wx.StaticText(panel, -1, "下单成功!", pos=(60, 20))
        self.button = wx.Button(panel, -1, "确定", pos=(50, 50), size=(80, 40))
        self.Bind(wx.EVT_BUTTON, self.pok, self.button)

    def pok(self, event):
        self.Close()




class TakeOrder(wx.Frame):
    def __init__(self, p, t):
        wx.Frame.__init__(self, id=-1, parent=p, title=t, size=(700, 600))
        # id=-1表示任意ID
        panel = wx.Panel(self, -1)

        # 接单:

        self.txt1 = wx.StaticText(panel, -1, "接单:", pos=(30, 25))

        # 接单列表
        self.list = wx.ListBox(panel, -1, choices=menu4, style=wx.LB_SINGLE, pos=(30, 50), size=(630, 320))

        self.txt2 = wx.StaticText(panel, -1, "请输入接单编号:", pos=(30, 400))

        self.text4 = wx.TextCtrl(panel, -1, pos=(30, 430), size=(180, -1))

        self.button2 = wx.Button(panel, -1, "接单", pos=(30, 480), size=(220, 40))
        # self.button2.SetFont(font1)
        self.Bind(wx.EVT_BUTTON, self.jiedan, self.button2)


    def jiedan(self, event):
        global num
        num2 =num
        takeNumber = self.text4.GetValue()
        newww = {
     }


        i = 1
        for tempInfo in menu3:
            if i == int(takeNumber):
                newww['num'] = tempInfo['num']
                newww['num2'] = str(num2)
                newww['phone'] = tempInfo['phone']
                newww['address'] = tempInfo['address']
                newww['window'] = tempInfo['window']
                newww['name'] = tempInfo['name']
                newww['price'] = tempInfo['price']

            i += 1
        menu5.append(newww)

        writeMenu6()

        f = open('menu5.txt', 'w')
        f.write(str(menu5))
        f.close()

        delnum = int(takeNumber)-1

        del menu3[delnum]

        f = open('menu3.txt', 'w')
        f.write(str(menu3))
        f.close()

        writeMenu4()

        read()

        frame01 = TakeOrderOK(None, "提示")
        frame01.Show(True)

        self.Close()

def writeMenu6():
    if os.path.exists('menu6.txt'):
        os.remove('menu6.txt')

    menu6 = []
    title = '编号\t\t下单用户\t\t接单用户\t\t窗口\t\t名称\t\t价格        电话                  地址\t\t'
    menu6.append(title)
    j = 1
    for tempInfo in menu5:
        new = str(j) + '\t\t' + tempInfo['num'] + '\t\t\t' + tempInfo['num2'] + '\t\t\t' + tempInfo['window'] + '\t\t' + tempInfo['name'] + '\t\t' + tempInfo['price'] + '         ' + tempInfo['phone'] + '     ' + tempInfo['address'] + '\t\t'
        j += 1
        menu6.append(new)

    f = open('menu6.txt', 'w')
    f.write(str(menu6))
    f.close()


class TakeOrderOK(wx.Frame):
    def __init__(self, p, t):
        wx.Frame.__init__(self, id=-1, parent=p, title=t, size=(200, 120))
        # id=-1表示任意ID
        panel = wx.Panel(self, -1)

        self.txt = wx.StaticText(panel, -1, "接单成功!", pos=(60, 20))
        self.button = wx.Button(panel, -1, "确定", pos=(50, 50), size=(80, 40))
        self.Bind(wx.EVT_BUTTON, self.tok, self.button)

    def tok(self, event):
        self.Close()



class DetailFrame(wx.Frame):
    def __init__(self, p, t):
        wx.Frame.__init__(self, id=-1, parent=p, title=t, size=(800, 600))
        # id=-1表示任意ID
        panel = wx.Panel(self, -1)

        # 我下的单、我接的单:

        self.xia = wx.StaticText(panel, -1, "订单记录", pos=(10, 15))
        self.xia = wx.ListBox(panel, -1, choices=menu6, style=wx.LB_SINGLE, pos=(10, 35), size=(770, 530))



def main():
    # recoverData()
    while True:
        printMenu()  # 打印菜单
        key = int(input('请输入功能对应的数字:'))
        if key == 1:
            addInfo()  # 添加菜品
        elif key == 2:
            delInfo()  # 删除菜品
        elif key == 3:
            modifyfdInfo()  # 修改菜品
        elif key == 4:
            showfdInfo()  # 查看所有菜品
        elif key == 5:
            saveToFile()  # 保存菜单到文件
        elif key == 0:  # 退出系统
            break


# 打印功能提示
def printMenu():
    print('=' * 30)
    print('菜品管理系统v1.0')
    print('1.添加菜品')
    print('2.删除菜品')
    print('3.修改菜品')
    print('4.显示所有菜品')
    print('5.保存数据')
    print('0.退出系统')
    print('=' * 30)


# 添加菜品信息
def addInfo():
    newwindow = input('输入新菜品的食堂窗口:')
    newname = input('输入新菜品的名字:')
    newprice = input('输入新菜品的价格:')
    newInfo = {
     }
    newInfo['window'] = newwindow
    newInfo['name'] = newname
    newInfo['price'] = newprice
    fdInfo.append(newInfo)


# 删除菜品信息
def delInfo():
    delNum = int(input('请输入要删除的序号:')) - 1
    del fdInfo[delNum]


# 修改菜品信息
def modifyfdInfo():
    fdId = int(input('请输入要修改的菜品序号:')) - 1
    newwindow = input('输入修改后菜品的窗口:')
    newname = input('输入修改后菜品的名字:')
    newprice = input('输入修改后菜品的价格:')
    fdInfo[fdId]['window'] = newwindow
    fdInfo[fdId]['name'] = newname
    fdInfo[fdId]['price'] = newprice


# 显示所有菜品信息
def showfdInfo():
    print('=' * 30)
    print('菜品信息如下:')
    print('=' * 30)
    i = 1
    for tempInfo in fdInfo:
        print('%d  %s  %s  %s' % (i, tempInfo['window'], tempInfo['name'], tempInfo['price']))
        i += 1


# 保存菜品信息
def saveToFile():
    f = open('backup.txt', 'w')
    f.write(str(fdInfo))
    f.close()
    WriteMenu()


# 读取数据
def recoverData():
    global fdInfo
    f = open('backup.txt')
    content = f.read()
    fdInfo = eval(content)
    f.close()


def WriteMenu():
    menu2 = []
    title = '编号\t\t窗口\t\t名称\t\t\t价格\t\t'
    menu2.append(title)
    j = 1
    for tempInfo in fdInfo:
        new = str(j) + '\t\t' + tempInfo['window'] + '\t\t' + tempInfo['name'] + '\t\t'+ tempInfo['price'] + '\t\t'
        j += 1
        menu2.append(new)

    if os.path.exists('menu2.txt'):
        os.remove('menu2.txt')

    f = open('menu2.txt', 'w')
    f.write(str(menu2))
    f.close()


if __name__ == "__main__":
    recoverData()
    # 创建应用程序
    app = wx.App(False)
    # frame就是应用程序的主窗口
    frame = Load(None, "登陆")
    # frame = MainFrame(None, "登陆")
    frame.Show(True)  # 显示该窗口
    app.MainLoop()  # 进入消息循环

需要这几个txt文件,内容都是[]**科技大学 创新指导与实践3 python食堂捎带系统_第1张图片

你可能感兴趣的:(python,经验分享)