12
Сен
2022

-805306369 выдаёт ошибку, методом изменения на просто except: у меня вышло что как раз в блоке try except ошибка

Вот код запускаемого файла

import Back_end as Calc
from PyQt5 import QtWidgets, QtGui
from PyQt5.QtCore import Qt
from gui import Ui_MainWindow
import sys


class MyWindow(QtWidgets.QDialog):

    def __init__(self):
        super(MyWindow, self).__init__()
        self.ui = Ui_MainWindow()

        self.ui.setupUi(self)

        self.ui.XP.setFont(
            QtGui.QFont('Times new roman', 24)
        )
        self.ui.XP.setAlignment(Qt.AlignHCenter | Qt.AlignCenter)
        self.ui.t1.setAlignment(Qt.AlignHCenter | Qt.AlignCenter)
        self.ui.t2.setAlignment(Qt.AlignHCenter | Qt.AlignCenter)
        self.ui.XP.setText("XP")

        def firstr():
            if self.ui.dif.currentIndex() == 0 or 2:
                return Calc.Round(1)
            elif self.ui.dif.currentIndex() == 1:
                return Calc.Round(31)
            elif self.ui.dif.currentIndex() == 3:
                return Calc.Round(3)
            elif self.ui.dif.currentIndex() == 4:
                return Calc.Round(6)

        def finalr():
            if self.ui.dif.currentIndex() == 0:
                return Calc.Round(40)
            elif self.ui.dif.currentIndex() == 1 or 2:
                return Calc.Round(60)
            elif self.ui.dif.currentIndex() == 3:
                return Calc.Round(80)
            elif self.ui.dif.currentIndex() == 4:
                return Calc.Round(100)

        def clicked():
            try:
                """dif = 1 if self.ui.dif1.isChecked() else 1.1 if self.ui.dif2.isChecked() else 1.2 if self.ui.dif3.isChecked() else 1.3 if self.ui.dif4.isChecked() else 'err'
                game = Calc.Game(Calc.Round(int(self.ui.FirstR.text())), Calc.Round(int(self.ui.FinalR.text())), dif)"""

                game = Calc.Game(firstr(), finalr(), 1 + (self.ui.mapdif.currentIndex() / 10))

                self.ui.XP.setText(str(game.xptoandfromround(int(self.ui.FirstR.text()), int(self.ui.FinalR.text()))) + " XP")

            except NameError:
                self.ui.XP.setText("ERROR")
        def difchange():
            if self.ui.dif.currentIndex() == 0 or 2:
                self.ui.FirstR.setMinimum(1)
                self.ui.FinalR.setMinimum(1)
            elif self.ui.dif.currentIndex() == 1:
                self.ui.FirstR.setMinimum(31)
                self.ui.FinalR.setMinimum(31)
            elif self.ui.dif.currentIndex() == 3:
                self.ui.FirstR.setMinimum(3)
                self.ui.FinalR.setMinimum(3)
            elif self.ui.dif.currentIndex() == 4:
                self.ui.FirstR.setMinimum(6)
                self.ui.FinalR.setMinimum(6)

        self.ui.dif.activated.connect(difchange)
        self.ui.calc.clicked.connect(clicked)


app = QtWidgets.QApplication(sys.argv)
application = MyWindow()
application.show()
sys.exit(app.exec())

Вот Back_end.py

class Round:
    def __init__(self, r):
        self.round = r
        self.bonus = 20

        for i in range(0, r if r < 20 else 20):
            self.bonus += 20
        if r > 20:
            for i in range(20, r if r < 50 else 50):
                self.bonus += 40
        if r > 50:
            for i in range(50, r):
                self.bonus += 90

    def roundup(self):
        self.round += 1
        self.bonus += 20 if self.round < 21 else 40 if self.round < 51 else 90

    def __eq__(self, other):
        return self.round == other.round

    def __gt__(self, other):
        return self.round > other.round


class Game:
    def __init__(self, firstr: Round, finalr: Round, difb: float = 1):
        self.firstR = firstr
        self.finalR = finalr
        self.currentRound = firstr
        self.mapDifBonus = difb
        self.xpForGame = 0
        self.gotXP = 0
        for i in range(self.firstR.round, self.finalR.round + 1):
            self.xpForGame += int(firstr.bonus * difb)
            firstr.roundup()

    def roundup(self):
        self.gotXP += int(self.currentRound.bonus * self.mapDifBonus) / 0.1 if self.currentRound > self.finalR else 1
        self.currentRound.roundup()

    def xptoandfromround(self, firstr: int, finalr: int):
        temp = self

        while temp.currentRound.round != firstr:
            temp.roundup()
        temp.gotXP = 0

        for i in range(firstr, finalr + 1):
            temp.roundup()
        return temp.gotXP

а вот gui.py

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'gui.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(624, 120)
        MainWindow.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
        MainWindow.setSizeGripEnabled(True)
        MainWindow.setModal(True)
        self.FirstR = QtWidgets.QSpinBox(MainWindow)
        self.FirstR.setGeometry(QtCore.QRect(0, 90, 71, 31))
        self.FirstR.setMinimum(1)
        self.FirstR.setMaximum(1000000000)
        self.FirstR.setObjectName("FirstR")
        self.FinalR = QtWidgets.QSpinBox(MainWindow)
        self.FinalR.setGeometry(QtCore.QRect(70, 90, 61, 31))
        self.FinalR.setMinimum(1)
        self.FinalR.setMaximum(1000000000)
        self.FinalR.setObjectName("FinalR")
        self.t1 = QtWidgets.QTextBrowser(MainWindow)
        self.t1.setGeometry(QtCore.QRect(70, 60, 61, 31))
        self.t1.setObjectName("t1")
        self.t2 = QtWidgets.QTextBrowser(MainWindow)
        self.t2.setGeometry(QtCore.QRect(0, 60, 71, 31))
        self.t2.setObjectName("t2")
        self.calc = QtWidgets.QPushButton(MainWindow)
        self.calc.setGeometry(QtCore.QRect(130, 60, 75, 62))
        self.calc.setObjectName("calc")
        self.XP = QtWidgets.QLabel(MainWindow)
        self.XP.setGeometry(QtCore.QRect(200, 60, 421, 61))
        self.XP.setObjectName("XP")
        self.dif = QtWidgets.QComboBox(MainWindow)
        self.dif.setGeometry(QtCore.QRect(0, 0, 312, 61))
        font = QtGui.QFont()
        font.setPointSize(30)
        font.setBold(False)
        font.setWeight(50)
        self.dif.setFont(font)
        self.dif.setEditable(False)
        self.dif.setObjectName("dif")
        self.dif.addItem("")
        self.dif.addItem("")
        self.dif.addItem("")
        self.dif.addItem("")
        self.dif.addItem("")
        self.mapdif = QtWidgets.QComboBox(MainWindow)
        self.mapdif.setGeometry(QtCore.QRect(312, 0, 312, 61))
        font = QtGui.QFont()
        font.setPointSize(30)
        self.mapdif.setFont(font)
        self.mapdif.setEditable(False)
        self.mapdif.setObjectName("mapdif")
        self.mapdif.addItem("")
        self.mapdif.addItem("")
        self.mapdif.addItem("")
        self.mapdif.addItem("")

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

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Xp Calculator"))
        MainWindow.setWhatsThis(_translate("MainWindow", "<html><head/><body><p>Calculate XP</p></body></html>"))
        self.t1.setHtml(_translate("MainWindow", "<!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.t2.setHtml(_translate("MainWindow", "<!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.calc.setText(_translate("MainWindow", "Calculate"))
        self.XP.setText(_translate("MainWindow", "TextLabel"))
        self.dif.setItemText(0, _translate("MainWindow", "Easy"))
        self.dif.setItemText(1, _translate("MainWindow", "Deflation"))
        self.dif.setItemText(2, _translate("MainWindow", "Medium"))
        self.dif.setItemText(3, _translate("MainWindow", "Hard"))
        self.dif.setItemText(4, _translate("MainWindow", "Imp./Chimps"))
        self.mapdif.setItemText(0, _translate("MainWindow", "Beginner"))
        self.mapdif.setItemText(1, _translate("MainWindow", "Intermediate"))
        self.mapdif.setItemText(2, _translate("MainWindow", "Advanced"))
        self.mapdif.setItemText(3, _translate("MainWindow", "Expert"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QDialog()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

Источник: https://ru.stackoverflow.com/questions/1448000/805306369-%D0%B2%D1%8B%D0%B4%D0%B0%D1%91%D1%82-%D0%BE%D1%88%D0%B8%D0%B1%D0%BA%D1%83-%D0%BC%D0%B5%D1%82%D0%BE%D0%B4%D0%BE%D0%BC-%D0%B8%D0%B7%D0%BC%D0%B5%D0%BD%D0%B5%D0%BD%D0%B8%D1%8F-%D0%BD%D0%B0-%D0%BF%D1%80%D0%BE%D1%81%D1%82%D0%BE-except-%D1%83-%D0%BC%D0%B5%D0%BD%D1%8F-%D0%B2%D1%8B%D1%88%D0%BB%D0%BE-%D1%87%D1%82%D0%BE-%D0%BA

Тебе может это понравится...

Добавить комментарий