当前位置:首页 >> 脚本专栏

python+pyqt5实现KFC点餐收银系统

本文实例为大家分享了python实现KFC点餐收银系统的具体代码,供大家参考,具体内容如下

这个kfc收银系统我实现了的以下功能:

1.正常餐品结算和找零。
2.基本套餐结算和找零。
3.使用优惠劵购买餐品结算和找零。
4.可在一定时间段参与店内活动
5.模拟打印小票的功能(写到文件中)。

工程文件:

python+pyqt5实现KFC点餐收银系统

肯德基.py文件实现各功能、kfctip.txt文件用于打印小票、picture文件里存放界面所需的图片、其他四个文件为各界面布局。

主界面:

python+pyqt5实现KFC点餐收银系统

正常餐品点餐界面:

python+pyqt5实现KFC点餐收银系统

套餐点餐界面:

python+pyqt5实现KFC点餐收银系统

活动套餐点餐界面:

python+pyqt5实现KFC点餐收银系统

当点击第二个活动套餐时:

python+pyqt5实现KFC点餐收银系统

加入订单点击返回后主界面会生成订单信息:

python+pyqt5实现KFC点餐收银系统

点击结算:

python+pyqt5实现KFC点餐收银系统
python+pyqt5实现KFC点餐收银系统
python+pyqt5实现KFC点餐收银系统

打印小票到文件:

python+pyqt5实现KFC点餐收银系统

以下是代码实现:

界面布局均使用pyqt5

主界面布局:

from PyQt5 import QtCore, QtWidgets

class Ui_MainWindow(object):
 def setupUi(self, MainWindow):
 MainWindow.setObjectName("MainWindow")
 MainWindow.resize(893, 489)
 self.centralwidget = QtWidgets.QWidget(MainWindow)
 self.centralwidget.setObjectName("centralwidget")
 self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
 self.pushButton_2.setGeometry(QtCore.QRect(510, 20, 101, 41))
 self.pushButton_2.setObjectName("pushButton_2")
 self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
 self.pushButton_3.setGeometry(QtCore.QRect(510, 80, 101, 41))
 self.pushButton_3.setObjectName("pushButton_3")
 self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
 self.pushButton_4.setGeometry(QtCore.QRect(510, 140, 101, 41))
 self.pushButton_4.setObjectName("pushButton_4")
 self.label = QtWidgets.QLabel(self.centralwidget)
 self.label.setGeometry(QtCore.QRect(510, 200, 111, 21))
 self.label.setObjectName("label")
 self.label_2 = QtWidgets.QLabel(self.centralwidget)
 self.label_2.setGeometry(QtCore.QRect(510, 230, 72, 15))
 self.label_2.setObjectName("label_2")
 self.label_3 = QtWidgets.QLabel(self.centralwidget)
 self.label_3.setGeometry(QtCore.QRect(590, 230, 21, 16))
 self.label_3.setObjectName("label_3")
 self.label_4 = QtWidgets.QLabel(self.centralwidget)
 self.label_4.setGeometry(QtCore.QRect(510, 260, 81, 21))
 self.label_4.setObjectName("label_4")
 self.label_5 = QtWidgets.QLabel(self.centralwidget)
 self.label_5.setGeometry(QtCore.QRect(510, 290, 72, 15))
 self.label_5.setObjectName("label_5")
 self.label_6 = QtWidgets.QLabel(self.centralwidget)
 self.label_6.setGeometry(QtCore.QRect(590, 290, 21, 16))
 self.label_6.setObjectName("label_6")
 self.label_7 = QtWidgets.QLabel(self.centralwidget)
 self.label_7.setGeometry(QtCore.QRect(640, 20, 61, 21))
 self.label_7.setObjectName("label_7")
 self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
 self.tableWidget.setGeometry(QtCore.QRect(640, 40, 241, 231))
 self.tableWidget.setObjectName("tableWidget")
 self.tableWidget.setColumnCount(3)
 self.tableWidget.setRowCount(0)
 item = QtWidgets.QTableWidgetItem()
 self.tableWidget.setHorizontalHeaderItem(0, item)
 item = QtWidgets.QTableWidgetItem()
 self.tableWidget.setHorizontalHeaderItem(1, item)
 item = QtWidgets.QTableWidgetItem()
 self.tableWidget.setHorizontalHeaderItem(2, item)
 self.tableWidget.horizontalHeader().setDefaultSectionSize(70)
 self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget)
 self.pushButton_5.setGeometry(QtCore.QRect(640, 290, 71, 31))
 self.pushButton_5.setObjectName("pushButton_5")
 self.pushButton_6 = QtWidgets.QPushButton(self.centralwidget)
 self.pushButton_6.setGeometry(QtCore.QRect(640, 350, 91, 31))
 self.pushButton_6.setObjectName("pushButton_6")
 self.pushButton_7 = QtWidgets.QPushButton(self.centralwidget)
 self.pushButton_7.setGeometry(QtCore.QRect(750, 350, 91, 31))
 self.pushButton_7.setObjectName("pushButton_7")
 self.label_8 = QtWidgets.QLabel(self.centralwidget)
 self.label_8.setGeometry(QtCore.QRect(10, 10, 481, 431))
 self.label_8.setObjectName("label_8")
 MainWindow.setCentralWidget(self.centralwidget)
 self.menubar = QtWidgets.QMenuBar(MainWindow)
 self.menubar.setGeometry(QtCore.QRect(0, 0, 893, 26))
 self.menubar.setObjectName("menubar")
 MainWindow.setMenuBar(self.menubar)
 self.statusbar = QtWidgets.QStatusBar(MainWindow)
 self.statusbar.setObjectName("statusbar")
 MainWindow.setStatusBar(self.statusbar)

 self.retranslateUi(MainWindow)
 QtCore.QMetaObject.connectSlotsByName(MainWindow)

 def retranslateUi(self, MainWindow):
 _translate = QtCore.QCoreApplication.translate
 MainWindow.setWindowTitle(_translate("MainWindow", "肯德基"))
 self.pushButton_2.setText(_translate("MainWindow", "基本餐"))
 self.pushButton_3.setText(_translate("MainWindow", "套餐"))
 self.pushButton_4.setText(_translate("MainWindow", "活动"))
 self.label.setText(_translate("MainWindow", "会员储值卡余额"))
 self.label_2.setText(_translate("MainWindow", "钱"))
 self.label_3.setText(_translate("MainWindow", "元"))
 self.label_4.setText(_translate("MainWindow", "您的优惠券"))
 self.label_5.setText(_translate("MainWindow", "券"))
 self.label_6.setText(_translate("MainWindow", "张"))
 self.label_7.setText(_translate("MainWindow", "您的订单"))
 item = self.tableWidget.horizontalHeaderItem(0)
 item.setText(_translate("MainWindow", "名称"))
 item = self.tableWidget.horizontalHeaderItem(1)
 item.setText(_translate("MainWindow", "数量"))
 item = self.tableWidget.horizontalHeaderItem(2)
 item.setText(_translate("MainWindow", "价格/元"))
 self.pushButton_5.setText(_translate("MainWindow", "删除"))
 self.pushButton_6.setText(_translate("MainWindow", "结算"))
 self.pushButton_7.setText(_translate("MainWindow", "打印小票"))
 self.label_8.setText(_translate("MainWindow", "图"))

正常套餐界面:

from PyQt5 import QtCore, QtWidgets

class Ui_Normal(object):
 def setupUi(self, Form):
 Form.setObjectName("Form")
 Form.resize(728, 459)
 self.pushButton = QtWidgets.QPushButton(Form)
 self.pushButton.setGeometry(QtCore.QRect(40, 190, 93, 41))
 self.pushButton.setObjectName("pushButton")
 self.pushButton_2 = QtWidgets.QPushButton(Form)
 self.pushButton_2.setGeometry(QtCore.QRect(260, 190, 93, 41))
 self.pushButton_2.setObjectName("pushButton_2")
 self.pushButton_3 = QtWidgets.QPushButton(Form)
 self.pushButton_3.setGeometry(QtCore.QRect(480, 190, 93, 41))
 self.pushButton_3.setObjectName("pushButton_3")
 self.pushButton_4 = QtWidgets.QPushButton(Form)
 self.pushButton_4.setGeometry(QtCore.QRect(40, 400, 93, 41))
 self.pushButton_4.setObjectName("pushButton_4")
 self.pushButton_5 = QtWidgets.QPushButton(Form)
 self.pushButton_5.setGeometry(QtCore.QRect(620, 400, 93, 41))
 self.pushButton_5.setObjectName("pushButton_5")
 self.pushButton_6 = QtWidgets.QPushButton(Form)
 self.pushButton_6.setGeometry(QtCore.QRect(260, 400, 93, 41))
 self.pushButton_6.setObjectName("pushButton_6")
 self.label = QtWidgets.QLabel(Form)
 self.label.setGeometry(QtCore.QRect(50, 170, 72, 15))
 self.label.setObjectName("label")
 self.label_2 = QtWidgets.QLabel(Form)
 self.label_2.setGeometry(QtCore.QRect(30, 140, 121, 21))
 self.label_2.setObjectName("label_2")
 self.label_3 = QtWidgets.QLabel(Form)
 self.label_3.setGeometry(QtCore.QRect(30, 10, 121, 111))
 self.label_3.setObjectName("label_3")
 self.label_4 = QtWidgets.QLabel(Form)
 self.label_4.setGeometry(QtCore.QRect(270, 170, 72, 15))
 self.label_4.setObjectName("label_4")
 self.label_5 = QtWidgets.QLabel(Form)
 self.label_5.setGeometry(QtCore.QRect(270, 140, 72, 15))
 self.label_5.setObjectName("label_5")
 self.label_6 = QtWidgets.QLabel(Form)
 self.label_6.setGeometry(QtCore.QRect(240, 10, 131, 111))
 self.label_6.setObjectName("label_6")
 self.label_7 = QtWidgets.QLabel(Form)
 self.label_7.setGeometry(QtCore.QRect(490, 170, 72, 15))
 self.label_7.setObjectName("label_7")
 self.label_8 = QtWidgets.QLabel(Form)
 self.label_8.setGeometry(QtCore.QRect(480, 140, 91, 16))
 self.label_8.setObjectName("label_8")
 self.label_9 = QtWidgets.QLabel(Form)
 self.label_9.setGeometry(QtCore.QRect(460, 10, 131, 111))
 self.label_9.setObjectName("label_9")
 self.label_10 = QtWidgets.QLabel(Form)
 self.label_10.setGeometry(QtCore.QRect(50, 380, 72, 15))
 self.label_10.setObjectName("label_10")
 self.label_11 = QtWidgets.QLabel(Form)
 self.label_11.setGeometry(QtCore.QRect(60, 360, 51, 16))
 self.label_11.setObjectName("label_11")
 self.label_12 = QtWidgets.QLabel(Form)
 self.label_12.setGeometry(QtCore.QRect(30, 250, 121, 101))
 self.label_12.setObjectName("label_12")
 self.label_13 = QtWidgets.QLabel(Form)
 self.label_13.setGeometry(QtCore.QRect(270, 380, 72, 15))
 self.label_13.setObjectName("label_13")
 self.label_14 = QtWidgets.QLabel(Form)
 self.label_14.setGeometry(QtCore.QRect(250, 360, 131, 16))
 self.label_14.setObjectName("label_14")
 self.label_15 = QtWidgets.QLabel(Form)
 self.label_15.setGeometry(QtCore.QRect(240, 250, 131, 101))
 self.label_15.setObjectName("label_15")

 self.retranslateUi(Form)
 QtCore.QMetaObject.connectSlotsByName(Form)

 def retranslateUi(self, Form):
 _translate = QtCore.QCoreApplication.translate
 Form.setWindowTitle(_translate("Form", "Form"))
 self.pushButton.setText(_translate("Form", "加入订单"))
 self.pushButton_2.setText(_translate("Form", "加入订单"))
 self.pushButton_3.setText(_translate("Form", "加入订单"))
 self.pushButton_4.setText(_translate("Form", "加入订单"))
 self.pushButton_5.setText(_translate("Form", "返回"))
 self.pushButton_6.setText(_translate("Form", "加入订单"))
 self.label.setText(_translate("Form", "钱1"))
 self.label_2.setText(_translate("Form", "新奥尔良烤鸡腿堡"))
 self.label_3.setText(_translate("Form", "TextLabel"))
 self.label_4.setText(_translate("Form", "钱2"))
 self.label_5.setText(_translate("Form", "香辣鸡翅"))
 self.label_6.setText(_translate("Form", "TextLabel"))
 self.label_7.setText(_translate("Form", "钱3"))
 self.label_8.setText(_translate("Form", "波纹霸王薯条"))
 self.label_9.setText(_translate("Form", "TextLabel"))
 self.label_10.setText(_translate("Form", "钱4"))
 self.label_11.setText(_translate("Form", "乌龙茶"))
 self.label_12.setText(_translate("Form", "TextLabel"))
 self.label_13.setText(_translate("Form", "钱5"))
 self.label_14.setText(_translate("Form", "原味圣代(草莓酱)"))
 self.label_15.setText(_translate("Form", "TextLabel"))

套餐界面:

from PyQt5 import QtCore, QtWidgets

class Ui_Package(object):
 def setupUi(self, Form):
 Form.setObjectName("Form")
 Form.resize(728, 393)
 self.pushButton = QtWidgets.QPushButton(Form)
 self.pushButton.setGeometry(QtCore.QRect(90, 280, 91, 31))
 self.pushButton.setObjectName("pushButton")
 self.pushButton_2 = QtWidgets.QPushButton(Form)
 self.pushButton_2.setGeometry(QtCore.QRect(340, 280, 93, 31))
 self.pushButton_2.setObjectName("pushButton_2")
 self.label = QtWidgets.QLabel(Form)
 self.label.setGeometry(QtCore.QRect(100, 250, 72, 15))
 self.label.setObjectName("label")
 self.label_2 = QtWidgets.QLabel(Form)
 self.label_2.setGeometry(QtCore.QRect(350, 250, 72, 15))
 self.label_2.setObjectName("label_2")
 self.label_3 = QtWidgets.QLabel(Form)
 self.label_3.setGeometry(QtCore.QRect(80, 220, 131, 21))
 self.label_3.setObjectName("label_3")
 self.label_4 = QtWidgets.QLabel(Form)
 self.label_4.setGeometry(QtCore.QRect(330, 220, 111, 21))
 self.label_4.setObjectName("label_4")
 self.label_5 = QtWidgets.QLabel(Form)
 self.label_5.setGeometry(QtCore.QRect(60, 20, 161, 171))
 self.label_5.setObjectName("label_5")
 self.label_6 = QtWidgets.QLabel(Form)
 self.label_6.setGeometry(QtCore.QRect(300, 20, 171, 171))
 self.label_6.setObjectName("label_6")
 self.pushButton_3 = QtWidgets.QPushButton(Form)
 self.pushButton_3.setGeometry(QtCore.QRect(560, 280, 101, 41))
 self.pushButton_3.setObjectName("pushButton_3")

 self.retranslateUi(Form)
 QtCore.QMetaObject.connectSlotsByName(Form)

 def retranslateUi(self, Form):
 _translate = QtCore.QCoreApplication.translate
 Form.setWindowTitle(_translate("Form", "Form"))
 self.pushButton.setText(_translate("Form", "加入订单"))
 self.pushButton_2.setText(_translate("Form", "加入订单"))
 self.label.setText(_translate("Form", "钱1"))
 self.label_2.setText(_translate("Form", "钱2"))
 self.label_3.setText(_translate("Form", "翅桶辣堡奥堡套餐"))
 self.label_4.setText(_translate("Form", "万圣节日劲堡桶"))
 self.label_5.setText(_translate("Form", "TextLabel"))
 self.label_6.setText(_translate("Form", "TextLabel"))
 self.pushButton_3.setText(_translate("Form", "返回"))

活动界面:

from PyQt5 import QtCore, QtWidgets

class Ui_Activity(object):
 def setupUi(self, Form):
 Form.setObjectName("Form")
 Form.resize(639, 335)
 self.pushButton = QtWidgets.QPushButton(Form)
 self.pushButton.setGeometry(QtCore.QRect(50, 240, 93, 31))
 self.pushButton.setObjectName("pushButton")
 self.pushButton_2 = QtWidgets.QPushButton(Form)
 self.pushButton_2.setGeometry(QtCore.QRect(300, 240, 93, 31))
 self.pushButton_2.setObjectName("pushButton_2")
 self.label = QtWidgets.QLabel(Form)
 self.label.setGeometry(QtCore.QRect(11, 220, 201, 20))
 self.label.setObjectName("label")
 self.label_2 = QtWidgets.QLabel(Form)
 self.label_2.setGeometry(QtCore.QRect(20, 200, 161, 16))
 self.label_2.setObjectName("label_2")
 self.label_3 = QtWidgets.QLabel(Form)
 self.label_3.setGeometry(QtCore.QRect(50, 180, 91, 16))
 self.label_3.setObjectName("label_3")
 self.label_4 = QtWidgets.QLabel(Form)
 self.label_4.setGeometry(QtCore.QRect(30, 30, 141, 141))
 self.label_4.setObjectName("label_4")
 self.label_5 = QtWidgets.QLabel(Form)
 self.label_5.setGeometry(QtCore.QRect(261, 220, 201, 20))
 self.label_5.setObjectName("label_5")
 self.label_6 = QtWidgets.QLabel(Form)
 self.label_6.setGeometry(QtCore.QRect(270, 200, 161, 16))
 self.label_6.setObjectName("label_6")
 self.label_7 = QtWidgets.QLabel(Form)
 self.label_7.setGeometry(QtCore.QRect(310, 180, 61, 16))
 self.label_7.setObjectName("label_7")
 self.label_8 = QtWidgets.QLabel(Form)
 self.label_8.setGeometry(QtCore.QRect(280, 30, 151, 141))
 self.label_8.setObjectName("label_8")
 self.pushButton_3 = QtWidgets.QPushButton(Form)
 self.pushButton_3.setGeometry(QtCore.QRect(490, 250, 101, 31))
 self.pushButton_3.setObjectName("pushButton_3")

 self.retranslateUi(Form)
 QtCore.QMetaObject.connectSlotsByName(Form)

 def retranslateUi(self, Form):
 _translate = QtCore.QCoreApplication.translate
 Form.setWindowTitle(_translate("Form", "Form"))
 self.pushButton.setText(_translate("Form", "加入订单"))
 self.pushButton_2.setText(_translate("Form", "加入订单"))
 self.label.setText(_translate("Form", "钱1"))
 self.label_2.setText(_translate("Form", "2018.10.1-2018.10.31"))
 self.label_3.setText(_translate("Form", "葡式蛋挞5只"))
 self.label_4.setText(_translate("Form", "TextLabel"))
 self.label_5.setText(_translate("Form", "钱2"))
 self.label_6.setText(_translate("Form", "2018.11.1-2018.11.11"))
 self.label_7.setText(_translate("Form", "超级翅桶"))
 self.label_8.setText(_translate("Form", "TextLabel"))
 self.pushButton_3.setText(_translate("Form", "返回"))

以下为实现各界面互联和各功能的实现(注释比较详细这里就不多说了):

# -*- coding: utf-8 -*-
# 作者:dcjmessi
# 日期:2018/10/19


from kfcmain import *
from normal import *
from package import *
from activity import *
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QPixmap

class KFC_Main(QMainWindow):
 def __init__(self):
 QMainWindow.__init__(self)
 self.main_ui = Ui_MainWindow()
 self.main_ui.setupUi(self)

 # 给按钮绑定方法
 btn_del = self.main_ui.pushButton_5
 btn_del.clicked.connect(self.order_del)
 btn_num = self.main_ui.pushButton_6
 btn_num.clicked.connect(self.order_num)
 self.btn_tip = self.main_ui.pushButton_7
 self.btn_tip.clicked.connect(self.order_tip)
 # 设置按钮为当前不可用
 self.btn_tip.setEnabled(False)
 # 定义列表
 self.num = []
 self.new_num = []

 # 主界面显示
 def person(self):
 # 主界面贴图
 self.main_ui.label_8.setPixmap(QPixmap('./picture/主界图.png'))
 # 将图片完全填充
 self.main_ui.label_8.setScaledContents(True)
 # 初始化会员储值余额
 self.balance = 200
 # 初始化优惠券数量
 self.coupons = 1
 # 显示余额和券数量
 self.main_ui.label_2.setText(str(self.balance))
 self.main_ui.label_5.setText(str(self.coupons))
 # 显示主界面
 kfcmain.show()

 # 删除tableWidget所选行
 def order_del(self):
 # 获取所选行索引
 row_index = kfcmain.main_ui.tableWidget.currentRow()
 if row_index != -1:
  # 删除
  kfcmain.main_ui.tableWidget.removeRow(row_index)

 # 结算
 def order_num(self):
 # 设置按钮为可用
 self.btn_tip.setEnabled(True)
 # 遍历所有行
 for row_index in range(kfcmain.main_ui.tableWidget.rowCount()):
  # 将每一行的第三项值添加到num列表里
  self.num.append(kfcmain.main_ui.tableWidget.item(row_index, 2).text())

 # 将num中的字符转换成int型
 self.new_num = eval('[' + (','.join(self.num)) + ']')
 # 将new_num列表值求和
 self.money = sum(self.new_num)

 # 有优惠券时
 if self.coupons >= 1:
  # 消息提示框
  button = QMessageBox.information(self, "温馨提示", "是否使用优惠券", QMessageBox.Yes | QMessageBox.No)
  # 使用优惠券
  if button == QMessageBox.Yes:
  # 当前优惠券数量减一
  self.coupons = self.coupons -1
  self.main_ui.label_5.setText(str(self.coupons))

  # 余额足够
  if self.balance >= (self.money - self.coupons * 20):
   QMessageBox.information(self, "恭喜您", "付款成功!", QMessageBox.Yes)
   self.balance = self.balance - self.money - self.coupons * 20
   self.main_ui.label_2.setText(str(self.balance))
  else:
   QMessageBox.information(self, "对不起", "您的会员储值卡余额不足!", QMessageBox.Yes)
  # 不使用优惠券
  else:
  if self.balance >= self.money:
   QMessageBox.information(self, "恭喜您", "付款成功!", QMessageBox.Yes)
   self.balance = self.balance - self.money
   self.main_ui.label_2.setText(str(self.balance))
  else:
   QMessageBox.information(self, "对不起", "您的会员储值卡余额不足!", QMessageBox.Yes)
 # 没有优惠券时
 else:
  if self.balance >= self.money:
  QMessageBox.information(self, "恭喜您", "付款成功!", QMessageBox.Yes)
  self.balance = self.balance - self.money
  self.main_ui.label_2.setText(str(self.balance))
  else:
  QMessageBox.information(self, "对不起", "您的会员储值卡余额不足!", QMessageBox.Yes)

 # 打印小票
 def order_tip(self):
 # 打开本地txt文件
 with open("kfctip.txt", "w") as f:
  # 遍历行
  for row_index in range(kfcmain.main_ui.tableWidget.rowCount()):
  # 遍历列
  for column_index in range(kfcmain.main_ui.tableWidget.columnCount()):
   # 将tableWidget数据写入文件
   f.write(kfcmain.main_ui.tableWidget.item(row_index, column_index).text() + "\n")
  f.write("合计:" + str(self.money) + "元")
 f.close()

class Normal(QWidget):
 def __init__(self):
 QWidget.__init__(self)
 self.normal_ui = Ui_Normal()
 self.normal_ui.setupUi(self)

 # 初始化各基本餐加入订单按钮点击次数
 self.bt1 = 0
 self.bt2 = 0
 self.bt3 = 0
 self.bt4 = 0
 self.bt6 = 0
 # 初始化返回按钮点击次数
 self.bt5 = 0
 # 按钮绑定方法
 btn_hamburg = self.normal_ui.pushButton
 btn_hamburg.clicked.connect(self.order_hamburg)
 btn_chicken = self.normal_ui.pushButton_2
 btn_chicken.clicked.connect(self.order_chicken)
 btn_fries = self.normal_ui.pushButton_3
 btn_fries.clicked.connect(self.order_fries)
 btn_tea = self.normal_ui.pushButton_4
 btn_tea.clicked.connect(self.order_tea)
 btn_ice = self.normal_ui.pushButton_6
 btn_ice.clicked.connect(self.order_ice)
 btn_return = self.normal_ui.pushButton_5
 btn_return.clicked.connect(self.nor_show)

 # 显示基本餐界面
 def nor_order(self):
 self.normal_ui.label_3.setPixmap(QPixmap('./picture/新奥尔良.png'))
 self.normal_ui.label_3.setScaledContents(True)
 self.normal_ui.label_6.setPixmap(QPixmap('./picture/鸡翅.png'))
 self.normal_ui.label_6.setScaledContents(True)
 self.normal_ui.label_9.setPixmap(QPixmap('./picture/薯条.png'))
 self.normal_ui.label_9.setScaledContents(True)
 self.normal_ui.label_12.setPixmap(QPixmap('./picture/乌龙茶.png'))
 self.normal_ui.label_12.setScaledContents(True)
 self.normal_ui.label_15.setPixmap(QPixmap('./picture/冰淇淋.png'))
 self.normal_ui.label_15.setScaledContents(True)
 # 基本餐价格
 self.price_hamburg = 18.5
 self.price_chicken = 11.0
 self.price_fries = 13.0
 self.price_tea = 13.5
 self.price_ice = 10.0
 # 显示价格
 self.normal_ui.label.setText(str(self.price_hamburg)+"元/份")
 self.normal_ui.label_4.setText(str(self.price_chicken)+"元/份")
 self.normal_ui.label_7.setText(str(self.price_fries)+"元/份")
 self.normal_ui.label_10.setText(str(self.price_tea)+"元/份")
 self.normal_ui.label_13.setText(str(self.price_ice)+"元/份")
 normal.show()

 # 计算点击次数
 def order_hamburg(self):
 self.bt1 += 1

 def order_chicken(self):
 self.bt2 += 1

 def order_fries(self):
 self.bt3 += 1

 def order_tea(self):
 self.bt4 += 1

 def order_ice(self):
 self.bt6 += 1

 def nor_show(self):
 self.bt5 += 1

 # 隐藏界面
 normal.hide()

 # 获取所选各基本餐的数量对应的价格
 self.num_hamburg = self.price_hamburg * self.bt1
 self.num_chicken = self.price_chicken * self.bt2
 self.num_fries = self.price_fries * self.bt3
 self.num_tea = self.price_tea * self.bt4
 self.num_ice = self.price_ice * self.bt6

 # 不是第一次进入该界面
 if self.bt5 > 1:
  for row_index in range(kfcmain.main_ui.tableWidget.rowCount()):
  # 获取tableWidget的所有名称,并放入name列表
  name.append(kfcmain.main_ui.tableWidget.item(row_index, 0).text())
  if '新奥尔良烤鸡腿堡' in name:
  # 重新设置该行的数量和价格
  kfcmain.main_ui.tableWidget.setItem(name.index('新奥尔良烤鸡腿堡'), 1, QTableWidgetItem("×" + str(self.bt1)))
  kfcmain.main_ui.tableWidget.setItem(name.index('新奥尔良烤鸡腿堡'), 2, QTableWidgetItem(str(self.num_hamburg)))
  if '新奥尔良烤鸡腿堡' not in name:
  # 已选择
  if self.bt1 != 0:
   # 添加一行数据
   row_count = kfcmain.main_ui.tableWidget.rowCount()
   kfcmain.main_ui.tableWidget.insertRow(row_count)
   kfcmain.main_ui.tableWidget.setItem(row_count, 0, QTableWidgetItem(normal.normal_ui.label_2.text()))
   kfcmain.main_ui.tableWidget.setItem(row_count, 1, QTableWidgetItem("×" + str(self.bt1)))
   kfcmain.main_ui.tableWidget.setItem(row_count, 2, QTableWidgetItem(str(self.num_hamburg)))
  if '香辣鸡翅' in name:
  kfcmain.main_ui.tableWidget.setItem(name.index('香辣鸡翅'), 1, QTableWidgetItem("×" + str(self.bt2)))
  kfcmain.main_ui.tableWidget.setItem(name.index('香辣鸡翅'), 2, QTableWidgetItem(str(self.num_chicken)))
  if '香辣鸡翅' not in name:
  if self.bt2 != 0:
   row_count = kfcmain.main_ui.tableWidget.rowCount()
   kfcmain.main_ui.tableWidget.insertRow(row_count)
   kfcmain.main_ui.tableWidget.setItem(row_count, 0, QTableWidgetItem(normal.normal_ui.label_5.text()))
   kfcmain.main_ui.tableWidget.setItem(row_count, 1, QTableWidgetItem("×" + str(self.bt2)))
   kfcmain.main_ui.tableWidget.setItem(row_count, 2, QTableWidgetItem(str(self.num_chicken)))
  if '波纹霸王薯条' in name:
  kfcmain.main_ui.tableWidget.setItem(name.index('波纹霸王薯条'), 1, QTableWidgetItem("×" + str(self.bt3)))
  kfcmain.main_ui.tableWidget.setItem(name.index('波纹霸王薯条'), 2, QTableWidgetItem(str(self.num_fries)))
  if '波纹霸王薯条' not in name:
  if self.bt3 != 0:
   row_count = kfcmain.main_ui.tableWidget.rowCount()
   kfcmain.main_ui.tableWidget.insertRow(row_count)
   kfcmain.main_ui.tableWidget.setItem(row_count, 0, QTableWidgetItem(normal.normal_ui.label_8.text()))
   kfcmain.main_ui.tableWidget.setItem(row_count, 1, QTableWidgetItem("×" + str(self.bt3)))
   kfcmain.main_ui.tableWidget.setItem(row_count, 2, QTableWidgetItem(str(self.num_fries)))
  if '乌龙茶'in name:
  kfcmain.main_ui.tableWidget.setItem(name.index('乌龙茶'), 1, QTableWidgetItem("×" + str(self.bt4)))
  kfcmain.main_ui.tableWidget.setItem(name.index('乌龙茶'), 2, QTableWidgetItem(str(self.num_tea)))
  if '乌龙茶' not in name:
  if self.bt4 != 0:
   row_count = kfcmain.main_ui.tableWidget.rowCount()
   kfcmain.main_ui.tableWidget.insertRow(row_count)
   kfcmain.main_ui.tableWidget.setItem(row_count, 0, QTableWidgetItem(normal.normal_ui.label_11.text()))
   kfcmain.main_ui.tableWidget.setItem(row_count, 1, QTableWidgetItem("×" + str(self.bt4)))
   kfcmain.main_ui.tableWidget.setItem(row_count, 2, QTableWidgetItem(str(self.num_tea)))
  if '原味圣代(草莓酱)' in name:
  kfcmain.main_ui.tableWidget.setItem(name.index('原味圣代(草莓酱)'), 1, QTableWidgetItem("×" + str(self.bt6)))
  kfcmain.main_ui.tableWidget.setItem(name.index('原味圣代(草莓酱)'), 2, QTableWidgetItem(str(self.num_ice)))
  if '原味圣代(草莓酱)' not in name:
  if self.bt6 != 0:
   row_count = kfcmain.main_ui.tableWidget.rowCount()
   kfcmain.main_ui.tableWidget.insertRow(row_count)
   kfcmain.main_ui.tableWidget.setItem(row_count, 0, QTableWidgetItem(normal.normal_ui.label_14.text()))
   kfcmain.main_ui.tableWidget.setItem(row_count, 1, QTableWidgetItem("×" + str(self.bt6)))
   kfcmain.main_ui.tableWidget.setItem(row_count, 2, QTableWidgetItem(str(self.num_ice)))
 # 第一次进入该界面
 else:
  if self.bt1 != 0:
  row_count = kfcmain.main_ui.tableWidget.rowCount()
  kfcmain.main_ui.tableWidget.insertRow(row_count)
  kfcmain.main_ui.tableWidget.setItem(row_count, 0, QTableWidgetItem(normal.normal_ui.label_2.text()))
  kfcmain.main_ui.tableWidget.setItem(row_count, 1, QTableWidgetItem("×" + str(self.bt1)))
  kfcmain.main_ui.tableWidget.setItem(row_count, 2, QTableWidgetItem(str(self.num_hamburg)))
  if self.bt2 != 0:
  row_count = kfcmain.main_ui.tableWidget.rowCount()
  kfcmain.main_ui.tableWidget.insertRow(row_count)
  kfcmain.main_ui.tableWidget.setItem(row_count, 0, QTableWidgetItem(normal.normal_ui.label_5.text()))
  kfcmain.main_ui.tableWidget.setItem(row_count, 1, QTableWidgetItem("×" + str(self.bt2)))
  kfcmain.main_ui.tableWidget.setItem(row_count, 2, QTableWidgetItem(str(self.num_chicken)))
  if self.bt3 != 0:
  row_count = kfcmain.main_ui.tableWidget.rowCount()
  kfcmain.main_ui.tableWidget.insertRow(row_count)
  kfcmain.main_ui.tableWidget.setItem(row_count, 0, QTableWidgetItem(normal.normal_ui.label_8.text()))
  kfcmain.main_ui.tableWidget.setItem(row_count, 1, QTableWidgetItem("×" + str(self.bt3)))
  kfcmain.main_ui.tableWidget.setItem(row_count, 2, QTableWidgetItem(str(self.num_fries)))
  if self.bt4 != 0:
  row_count = kfcmain.main_ui.tableWidget.rowCount()
  kfcmain.main_ui.tableWidget.insertRow(row_count)
  kfcmain.main_ui.tableWidget.setItem(row_count, 0, QTableWidgetItem(normal.normal_ui.label_11.text()))
  kfcmain.main_ui.tableWidget.setItem(row_count, 1, QTableWidgetItem("×" + str(self.bt4)))
  kfcmain.main_ui.tableWidget.setItem(row_count, 2, QTableWidgetItem(str(self.num_tea)))
  if self.bt6 != 0:
  row_count = kfcmain.main_ui.tableWidget.rowCount()
  kfcmain.main_ui.tableWidget.insertRow(row_count)
  kfcmain.main_ui.tableWidget.setItem(row_count, 0, QTableWidgetItem(normal.normal_ui.label_14.text()))
  kfcmain.main_ui.tableWidget.setItem(row_count, 1, QTableWidgetItem("×" + str(self.bt6)))
  kfcmain.main_ui.tableWidget.setItem(row_count, 2, QTableWidgetItem(str(self.num_ice)))

class Package(QWidget):
 def __init__(self):
 QWidget.__init__(self)
 self.package_ui = Ui_Package()
 self.package_ui.setupUi(self)

 # 初始化各套餐加入订单按钮点击次数
 self.bt1 = 0
 self.bt2 = 0
 # 初始化返回按钮点击次数
 self.bt3 = 0
 # 按钮绑定方法
 btn_pack1 = self.package_ui.pushButton
 btn_pack1.clicked.connect(self.order_pack1)
 btn_pack2 = self.package_ui.pushButton_2
 btn_pack2.clicked.connect(self.order_pack2)
 btn_return = self.package_ui.pushButton_3
 btn_return.clicked.connect(self.pac_show)

 # 显示套餐界面
 def pac_order(self):
 self.package_ui.label_5.setPixmap(QPixmap('./picture/套餐2.png'))
 self.package_ui.label_5.setScaledContents(True)
 self.package_ui.label_6.setPixmap(QPixmap('./picture/套餐1.png'))
 self.package_ui.label_6.setScaledContents(True)
 # 套餐价格
 self.price_pack1 = 89.0
 self.price_pack2 = 67.0
 self.package_ui.label.setText(str(self.price_pack1)+"元/份")
 self.package_ui.label_2.setText(str(self.price_pack2)+"元/份")
 package.show()

 def order_pack1(self):
 self.bt1 += 1

 def order_pack2(self):
 self.bt2 += 1

 def pac_show(self):
 self.bt3 += 1

 package.hide()

 self.num_pack1 = self.price_pack1 * self.bt1
 self.num_pack2 = self.price_pack2 * self.bt2

 if self.bt3 > 1:
  for row_index in range(kfcmain.main_ui.tableWidget.rowCount()):
  name.append(kfcmain.main_ui.tableWidget.item(row_index, 0).text())
  if '翅桶辣堡奥堡套餐' in name:
  kfcmain.main_ui.tableWidget.setItem(name.index('翅桶辣堡奥堡套餐'), 1, QTableWidgetItem("×" + str(self.bt1)))
  kfcmain.main_ui.tableWidget.setItem(name.index('翅桶辣堡奥堡套餐'), 2, QTableWidgetItem(str(self.num_pack1)))
  if '翅桶辣堡奥堡套餐' not in name:
  if self.bt1 != 0:
   row_count = kfcmain.main_ui.tableWidget.rowCount()
   kfcmain.main_ui.tableWidget.insertRow(row_count)
   kfcmain.main_ui.tableWidget.setItem(row_count, 0, QTableWidgetItem(package.package_ui.label_3.text()))
   kfcmain.main_ui.tableWidget.setItem(row_count, 1, QTableWidgetItem("×" + str(self.bt1)))
   kfcmain.main_ui.tableWidget.setItem(row_count, 2, QTableWidgetItem(str(self.num_pack1)))
  if '万圣节日劲堡桶' in name:
  kfcmain.main_ui.tableWidget.setItem(name.index('万圣节日劲堡桶'), 1, QTableWidgetItem("×" + str(self.bt2)))
  kfcmain.main_ui.tableWidget.setItem(name.index('万圣节日劲堡桶'), 2, QTableWidgetItem(str(self.num_pack2)))
  if '万圣节日劲堡桶' not in name:
  if self.bt2 != 0:
   row_count = kfcmain.main_ui.tableWidget.rowCount()
   kfcmain.main_ui.tableWidget.insertRow(row_count)
   kfcmain.main_ui.tableWidget.setItem(row_count, 0, QTableWidgetItem(package.package_ui.label_4.text()))
   kfcmain.main_ui.tableWidget.setItem(row_count, 1, QTableWidgetItem("×" + str(self.bt2)))
   kfcmain.main_ui.tableWidget.setItem(row_count, 2, QTableWidgetItem(str(self.num_pack2)))
 else:
  if self.bt1 != 0:
  row_count = kfcmain.main_ui.tableWidget.rowCount()
  kfcmain.main_ui.tableWidget.insertRow(row_count)
  kfcmain.main_ui.tableWidget.setItem(row_count, 0, QTableWidgetItem(package.package_ui.label_3.text()))
  kfcmain.main_ui.tableWidget.setItem(row_count, 1, QTableWidgetItem("×" + str(self.bt1)))
  kfcmain.main_ui.tableWidget.setItem(row_count, 2, QTableWidgetItem(str(self.num_pack1)))
  if self.bt2 != 0:
  row_count = kfcmain.main_ui.tableWidget.rowCount()
  kfcmain.main_ui.tableWidget.insertRow(row_count)
  kfcmain.main_ui.tableWidget.setItem(row_count, 0, QTableWidgetItem(package.package_ui.label_4.text()))
  kfcmain.main_ui.tableWidget.setItem(row_count, 1, QTableWidgetItem("×" + str(self.bt2)))
  kfcmain.main_ui.tableWidget.setItem(row_count, 2, QTableWidgetItem(str(self.num_pack2)))

class Activity(QWidget):
 def __init__(self):
 QWidget.__init__(self)
 self.activity_ui = Ui_Activity()
 self.activity_ui.setupUi(self)

 # 初始化各活动加入订单按钮点击次数
 self.bt1 = 0
 # 初始化返回按钮点击次数
 self.bt3 = 0
 # 绑定方法
 btn_act1 = self.activity_ui.pushButton
 btn_act1.clicked.connect(self.order_act1)
 btn_act2 = self.activity_ui.pushButton_2
 btn_act2.clicked.connect(self.order_act2)
 btn_return = self.activity_ui.pushButton_3
 btn_return.clicked.connect(self.act_show)

 def act_order(self):
 self.activity_ui.label_4.setPixmap(QPixmap('./picture/活动1.png'))
 self.activity_ui.label_4.setScaledContents(True)
 self.activity_ui.label_8.setPixmap(QPixmap('./picture/活动2.png'))
 self.activity_ui.label_8.setScaledContents(True)
 # 活动价格
 self.price_act1 = 29.0
 self.price_act2 = 69.0
 self.activity_ui.label.setText(str(self.price_act1) + "元/份 原价:"+str(self.price_act1 + 7) + "元/份")
 self.activity_ui.label_5.setText(str(self.price_act2) + "元/份 原价:"+str(self.price_act2 + 10) + "元/份")
 activity.show()

 def order_act1(self):
 self.bt1 += 1

 def order_act2(self):
 QMessageBox.information(self, "对不起", "活动还没有开始,敬请期待!", QMessageBox.Yes)

 def act_show(self):
 self.bt3 += 1

 activity.hide()

 self.num_act1 = self.price_act1 * self.bt1

 if self.bt3 > 1:
  for row_index in range(kfcmain.main_ui.tableWidget.rowCount()):
  name.append(kfcmain.main_ui.tableWidget.item(row_index, 0).text())
  if '葡式蛋挞5只' in name:
  kfcmain.main_ui.tableWidget.setItem(name.index('葡式蛋挞5只'), 1, QTableWidgetItem("×" + str(self.bt1)))
  kfcmain.main_ui.tableWidget.setItem(name.index('葡式蛋挞5只'), 2, QTableWidgetItem(str(self.num_act1)))
  if '葡式蛋挞5只' not in name:
  if self.bt1 != 0:
   row_count = kfcmain.main_ui.tableWidget.rowCount()
   kfcmain.main_ui.tableWidget.insertRow(row_count)
   kfcmain.main_ui.tableWidget.setItem(row_count, 0, QTableWidgetItem(activity.activity_ui.label_3.text()))
   kfcmain.main_ui.tableWidget.setItem(row_count, 1, QTableWidgetItem("×" + str(self.bt1)))
   kfcmain.main_ui.tableWidget.setItem(row_count, 2, QTableWidgetItem(str(self.num_act1)))
 else:
  if self.bt1 != 0:
  row_count = kfcmain.main_ui.tableWidget.rowCount()
  kfcmain.main_ui.tableWidget.insertRow(row_count)
  kfcmain.main_ui.tableWidget.setItem(row_count, 0, QTableWidgetItem(activity.activity_ui.label_3.text()))
  kfcmain.main_ui.tableWidget.setItem(row_count, 1, QTableWidgetItem("×" + str(self.bt1)))
  kfcmain.main_ui.tableWidget.setItem(row_count, 2, QTableWidgetItem(str(self.num_act1)))

if __name__=="__main__":
 app = QApplication(sys.argv)

 kfcmain = KFC_Main()
 normal = Normal()
 package = Package()
 activity = Activity()
 # 显示主界面
 kfcmain.person()
 # 绑定按钮
 btn_normal = kfcmain.main_ui.pushButton_2
 btn_normal.clicked.connect(normal.nor_order)
 btn_package = kfcmain.main_ui.pushButton_3
 btn_package.clicked.connect(package.pac_order)
 btn_activity = kfcmain.main_ui.pushButton_4
 btn_activity.clicked.connect(activity.act_order)
 # 初始化name列表
 name = []

 sys.exit(app.exec_())

删除只实现了同餐品在订单上的删除,没有实现数量的减少,可自行添加。

更多学习资料请关注专题《管理系统开发》。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。