Код из обучалки не работает.
from PyQt5 import QtWidgets
from gui import Ui_MainWindow
import sys
class mywindow(QtWidgets.QMainWindow):
def __init__(self):
super(mywindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
app = QtWidgets.QApplication([])
application = mywindow()
application.show()
sys.exit(app.exec())
Выдаёт такую ошибку
Traceback (most recent call last):
File "E:...\SomeName.py", line 3, in
from gui import Ui_MainWindow # импорт нашего сгенерированного файла
ImportError: cannot import name 'Ui_MainWindow' from 'gui' (E:...\gui.py)
gui.py
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog: object) -> object:
Dialog.setObjectName("Dialog")
Dialog.resize(355, 53)
Dialog.setSizeGripEnabled(True)
self.FirstR = QtWidgets.QSpinBox(Dialog)
self.FirstR.setGeometry(QtCore.QRect(0, 30, 71, 21))
self.FirstR.setObjectName("FirstR")
self.FinalR = QtWidgets.QSpinBox(Dialog)
self.FinalR.setGeometry(QtCore.QRect(70, 30, 61, 21))
self.FinalR.setObjectName("FinalR")
self.textBrowser = QtWidgets.QTextBrowser(Dialog)
self.textBrowser.setGeometry(QtCore.QRect(70, 0, 61, 31))
self.textBrowser.setObjectName("textBrowser")
self.textBrowser_2 = QtWidgets.QTextBrowser(Dialog)
self.textBrowser_2.setGeometry(QtCore.QRect(0, 0, 71, 31))
self.textBrowser_2.setObjectName("textBrowser_2")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(130, 0, 75, 61))
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(200, 0, 151, 51))
self.label.setText("")
self.label.setObjectName("label")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
Dialog.setWhatsThis(_translate("Dialog", "<html><head/><body><p>Calculate XP</p></body></html>"))
self.textBrowser.setHtml(_translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Last round</p></body></html>"))
self.textBrowser_2.setHtml(_translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">First round</p></body></html>"))
self.pushButton.setText(_translate("Dialog", "Calculate"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
gui,py