您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關怎么在python中使用pyqt5實現一個點餐收銀系統,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
Python是一種跨平臺的、具有解釋性、編譯性、互動性和面向對象的腳本語言,其最初的設計是用于編寫自動化腳本,隨著版本的不斷更新和新功能的添加,常用于用于開發獨立的項目和大型項目。
主界面布局:
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_())
以上就是怎么在python中使用pyqt5實現一個點餐收銀系統,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。