• 1000 *
import pkg_resources.py2_warn
from PyQt5 import QtCore, QtGui, QtWidgets
import barcode
from barcode.writer import ImageWriter
import shutil
import os
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(607, 503)
self.pushButton = QtWidgets.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(-170, 220, 93, 28))
self.pushButton.setObjectName("pushButton")
self.horizontalLayoutWidget = QtWidgets.QWidget(Form)
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(130, 180, 311, 80))
self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.lineEdit = QtWidgets.QLineEdit(self.horizontalLayoutWidget)
self.lineEdit.setObjectName("lineEdit")
self.horizontalLayout.addWidget(self.lineEdit)
self.pushButton_2 = QtWidgets.QPushButton(self.horizontalLayoutWidget)
self.pushButton_2.setObjectName("pushButton_2")
self.horizontalLayout.addWidget(self.pushButton_2)
self.pushButton_2.clicked.connect(lambda: self.testEan(self.lineEdit.text()))
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", "PushButton"))
self.pushButton_2.setText(_translate("Form", "Generate"))
def testEan(self, i):
EAN = barcode.get_barcode_class('code128')
s = '0' * (8 - len(str(i)) - 1) + str(i)
ean = EAN(s, writer=ImageWriter())
fullname = ean.save(str(i))
try:
os.mkdir("Barcode")
except FileExistsError:
pass
try:
shutil.move(fullname, "Barcode")
except:
pass
QtWidgets.QMessageBox().about(QtWidgets.QWidget(), "Info", "Success")
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
ПРИМЕЧАНИЕ: я импортировал pkg_resources.py2_warn
, потому что без него, когда я пытаюсь запустить приложение, он не выдает имя модуля pkg_resources.py2_warn
Traceback: (most recent call last)
File "Bar.py" line 37, in <lambda>
File "Bar.py" line 51, in testEan
File "site packages\barcode\base.py" line 68 in save
File "site packages\barcode\codex.py" line 261 in render
File "site packages\barcode\base.py" line 111 in render
File "site packages\barcode\writer.py" line 226 in render
File "site packages\barcode\writer.py" line 356 in _paint_text
File "site packages\PIL\ImageFont.py" line 648 in truetype
File "site packages\PIL\ImageFont.py" line 645 in freetype
File "site packages\PIL\ImageFont.py" line 193 in __init__
OsError : cannot open resource
OS : windows 10
Python : 3.8.3
Pyinstaller : 3.6
Есть ли способ преодолеть эту ошибку трассировки?