我遇到运行PyInstaller生成的.EXE文件的问题。生成了.EXE文件,但是一旦我运行.EXE,它就会跟随。
以下是我运行以生成.EXE文件的命令。
pyinstaller.exe --onefile --windowed milktest.py
我正在搜索并在不同的论坛和帖子上提供所有解决方案,但仍然没有运气。
修改: Follwing是我的代码
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
class MilkTest(QDialog):
def __init__(self):
QDialog.__init__(self)
self.FAT_MAX = 30.0
self.PROTEIN_MAX = 20.0
self.SNF_MAX = 10.0
self.RESAZURIN_MAX = 10.0
self.ACIDITY_MAX = 10.0
self.LACTOMETER_MAX = 20.0
self.REJECTED = "REJECTED"
self.ACCEPTED = "ACCEPTED"
self.HIGHEST_PRICE = "HIGHEST PRICE"
self.SECOND_PRICE = "SECOND PRICE"
self.THIRD_PRICE = "THIRD PRICE"
self.REJECTED_PRICE = "NO CATEGORY"
layout = QGridLayout()
l_name = QLabel("Name")
l_date = QLabel("Date")
l_fat = QLabel("Fat")
l_protein = QLabel("Protein")
l_snf = QLabel("SNF")
l_temperature = QLabel("Temperature(C)")
l_alcohol_test = QLabel("Alcohol")
l_resazurin = QLabel("Resazurin")
l_acidity = QLabel("Acidity")
l_inhibitor_test = QLabel("Inhibitor Test")
l_lactometer = QLabel("Lactometer")
l_points = QLabel("Points")
l_status = QLabel("Status")
self.l_gained_status = QLabel("N/A")
l_price = QLabel("Price Category")
self.l_gained_price = QLabel("N/A")
self.le_name = QLineEdit()
self.de_date = QDateEdit()
self.de_date.setCalendarPopup(True)
self.de_date.setDate(QDate.currentDate())
self.dsb_fat = QDoubleSpinBox()
self.dsb_fat.setMinimum(0.0)
self.dsb_fat.setMaximum(30.0)
self.dsb_fat.setSingleStep(0.10)
self.dsb_protein = QDoubleSpinBox()
self.dsb_protein.setMinimum(0.0)
self.dsb_protein.setMaximum(30.0)
self.dsb_protein.setSingleStep(0.10)
self.dsb_snf = QDoubleSpinBox()
self.dsb_snf.setMinimum(0.0)
self.dsb_snf.setMaximum(30.0)
self.dsb_snf.setSingleStep(0.10)
self.dsb_temperature = QDoubleSpinBox()
self.dsb_temperature.setMinimum(0.0)
self.dsb_temperature.setMaximum(100.0)
self.dsb_temperature.setSingleStep(0.10)
# bg_alcohol_test = QButtonGroup()
# rb_negative = QRadioButton("Negative")
# rb_positive = QRadioButton("Positive")
# bg_alcohol_test.addButton(rb_negative)
# bg_alcohol_test.addButton(rb_positive)
self.cb_alcohol_test = QComboBox()
self.cb_alcohol_test.addItems(["Negative", "Positive"])
self.cb_resazurin = QComboBox()
self.cb_resazurin.addItems(["Blue", "Light Blue", "Purple", "Purple Pink", "Light Pink", "Pink", "White"])
self.dsb_acidity = QDoubleSpinBox()
self.dsb_acidity.setMinimum(0.0)
self.dsb_acidity.setMaximum(10.0)
self.dsb_acidity.setSingleStep(0.10)
self.cb_inhibitor_test = QComboBox()
self.cb_inhibitor_test.addItems(["Negative", "Positive"])
self.dsb_lactometer = QDoubleSpinBox()
self.dsb_lactometer.setMinimum(0.0)
self.dsb_lactometer.setMaximum(100.0)
self.dsb_lactometer.setSingleStep(0.10)
self.pb_close = QPushButton("Close")
self.pb_reset = QPushButton("Reset")
self.pb_calculate = QPushButton("Calculate")
self.lcdn_points = QLCDNumber()
self.lcdn_points.setSmallDecimalPoint(True)
self.lcdn_points.display(0)
palette = self.lcdn_points.palette()
# foreground color
palette.setColor(palette.WindowText, QColor(32, 32, 32))
# background color
palette.setColor(palette.Background, QColor(32, 32, 32))
# "light" border
palette.setColor(palette.Light, QColor(32, 32, 32))
# "dark" border
palette.setColor(palette.Dark, QColor(153, 153, 255))
# set the palette
self.lcdn_points.setPalette(palette)
layout.addWidget(l_name, 0, 0)
layout.addWidget(self.le_name, 0, 1)
layout.addWidget(l_date, 0, 2)
layout.addWidget(self.de_date, 0, 3)
layout.addWidget(l_fat, 1, 0)
layout.addWidget(self.dsb_fat, 1, 1)
layout.addWidget(l_protein, 1, 2)
layout.addWidget(self.dsb_protein, 1, 3)
layout.addWidget(l_snf, 2, 0)
layout.addWidget(self.dsb_snf, 2, 1)
layout.addWidget(l_temperature, 2, 2)
layout.addWidget(self.dsb_temperature, 2, 3)
layout.addWidget(l_alcohol_test, 3, 0)
layout.addWidget(self.cb_alcohol_test, 3, 1)
layout.addWidget(l_resazurin, 3, 2)
layout.addWidget(self.cb_resazurin, 3, 3)
layout.addWidget(l_acidity, 4, 0)
layout.addWidget(self.dsb_acidity, 4, 1)
layout.addWidget(l_inhibitor_test, 4, 2)
layout.addWidget(self.cb_inhibitor_test, 4, 3)
layout.addWidget(l_lactometer, 5, 0)
layout.addWidget(self.dsb_lactometer, 5, 1)
layout.addWidget(l_points, 5, 2)
layout.addWidget(self.lcdn_points, 5, 3)
layout.addWidget(l_status, 6, 0)
layout.addWidget(self.l_gained_status, 6, 1)
layout.addWidget(l_price, 6, 2)
layout.addWidget(self.l_gained_price, 6, 3)
layout.addWidget(self.pb_close, 7, 1)
layout.addWidget(self.pb_reset, 7, 2)
layout.addWidget(self.pb_calculate, 7, 3)
self.pb_close.clicked.connect(self.close)
self.pb_reset.clicked.connect(self.reset)
self.pb_calculate.clicked.connect(self.calculate)
app_icon = QIcon()
app_icon.addFile('flask512.png', QSize(512, 512))
app_icon.addFile('flask256.png', QSize(256, 256))
app_icon.addFile('flask128.png', QSize(128, 128))
app_icon.addFile('flask64.png', QSize(64, 64))
app_icon.addFile('flask32.png', QSize(32, 32))
app_icon.addFile('flask24.png', QSize(24, 24))
app_icon.addFile('flask16.png', QSize(16, 16))
self.setWindowIcon(app_icon)
self.setWindowTitle("MILK TEST")
self.setLayout(layout)
def reset(self):
self.le_name.setText("")
self.de_date.setDate(QDate.currentDate())
self.dsb_fat.setValue(0.0)
self.dsb_protein.setValue(0.0)
self.dsb_snf.setValue(0.0)
self.dsb_temperature.setValue(0.0)
self.cb_alcohol_test.setCurrentIndex(0)
self.cb_resazurin.setCurrentIndex(0)
self.dsb_acidity.setValue(0.0)
self.cb_inhibitor_test.setCurrentIndex(0)
self.dsb_lactometer.setValue(0.0)
self.lcdn_points.display(0)
def calculate(self):
fat_points = 0.0
protein_points = 0.0
snf_points = 0.0
resazurin_points = 0.0
acidity_points = 0.0
lactometer_points = 0.0
points_gained = 0.0
points_percentage = 0
fat_val = self.dsb_fat.value()
protein_val = self.dsb_protein.value()
snf_val = self.dsb_snf.value()
resazurin_index = self.cb_resazurin.currentIndex()
acidity_val = self.dsb_acidity.value()
lactometer_val = self.dsb_lactometer.value()
TOTAL_MAX = (
self.FAT_MAX + self.PROTEIN_MAX + self.SNF_MAX + self.RESAZURIN_MAX + self.ACIDITY_MAX + self.LACTOMETER_MAX)
if (fat_val >= 3.7):
fat_points = 30.0
elif (fat_val <= 3.6 and fat_val >= 3.3):
fat_points = 20.0
elif (fat_val <= 3.2 and fat_val >= 2.8):
fat_points = 10.0
else:
fat_points = 5.0
if (protein_val >= 3.2):
protein_points = 20.0
elif (protein_val <= 3.1 and protein_val >= 2.8):
protein_points = 10.0
else:
protein_points = 5.0
if (snf_val >= 8.7):
snf_points = 10.0
elif (snf_val <= 8.6 and snf_val >= 7.9):
snf_points = 5.0
else:
snf_points = 0.0
if (resazurin_index == 0 or resazurin_index == 1 or resazurin_index == 2):
resazurin_points = 10.0
elif (resazurin_index == 3 or resazurin_index == 4):
resazurin_points = 5.0
else:
resazurin_points = 0.0
if (acidity_val >= 0.1 and acidity_val <= 0.26):
acidity_points = 10.0
else:
acidity_points = 0.0
if (lactometer_val >= 26.0 and lactometer_val <= 32.0):
lactometer_points = 20.0
else:
lactometer_points = 0.0
points_gained = (fat_points + protein_points + snf_points + resazurin_points + acidity_points + lactometer_points)
points_percentage = int((points_gained * 100) / TOTAL_MAX)
self.lcdn_points.display(points_percentage)
if(points_percentage >= 35 and self.cb_alcohol_test.currentIndex() == 0 and (self.cb_resazurin.currentIndex() == 0 or self.cb_resazurin.currentIndex() == 1 or self.cb_resazurin.currentIndex() == 2 or self.cb_resazurin.currentIndex() == 3 or self.cb_resazurin.currentIndex() == 4) and self.cb_inhibitor_test.currentIndex() == 0 and (self.dsb_temperature.value() >= 15 and self.dsb_temperature.value() <= 20)):
self.l_gained_status.setText(self.ACCEPTED)
else:
self.l_gained_status.setText(self.REJECTED)
if (points_percentage >= 80):
self.l_gained_price.setText(self.HIGHEST_PRICE)
elif (points_percentage < 80 and points_percentage >= 60):
self.l_gained_price.setText(self.SECOND_PRICE)
elif (points_percentage < 60 and points_percentage >= 45):
self.l_gained_price.setText(self.THIRD_PRICE)
elif (points_percentage < 45 and points_percentage >= 35):
self.l_gained_price.setText(self.FOURTH_PRICE)
else:
self.l_gained_price.setText(self.REJECTED_PRICE)
app = QApplication(sys.argv)
dialog = MilkTest()
dialog.show()
app.exec_()
请有人帮助我吗?。
非常感谢