29
Июн
2022

Ошибка AttributeError: __ enter __

У меня было написано приложение на Mysql, решил переделать его на sqlite3. Столкнулся с ошибкой, после нажатия кнопки продолжить в окне login вылезает ошибка: Traceback (most recent call last): File "c:\main1.py", line 223, in testImage with self.connection.cursor() as cursor: AttributeError: __ enter __

main.py

import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import (QApplication, QWidget, QPushButton, QLabel, QLineEdit, QGridLayout, QMessageBox, QVBoxLayout)
from titul import Ui_mainWindow
from login import Ui_Login
from test import Ui_Test
from resyltati import Ui_ResyltTest
import sqlite3
import random
from PyQt5.QtGui import QPixmap
from config import host, user, password, db_name

class MainWindow(QtWidgets.QMainWindow, Ui_mainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.setupUi(self)

        self.connection = sqlite3.connect( 'diplom.db')
        self.cursor = self.connection.cursor()

        self.Button_startTest.clicked.connect(self.openLogin)

        self.Button_Rezylt.clicked.connect(self.openResyltati)

    def openLeksia(self):
        self.leksia = LeksiaWindow()
        self.close()
        self.leksia.show()

    def openLogin(self):
        self.login = LoginWindow(self.connection)
        self.close()
        self.login.show()

    def openResyltati(self):
        
        self.resyltati = ResyltatiWindow(self.connection)
        self.close()
        self.resyltati.show()



class ResyltatiWindow(QtWidgets.QMainWindow, Ui_ResyltTest):
    def __init__(self, connection):
        super(ResyltatiWindow, self).__init__()
        self.setupUi(self)
        self.connection = connection
        self.cursor = self.connection.cursor()
        self.cursor.execute("SELECT * FROM students ")
        self.connection.commit()
        self.pushButtontomain_2.clicked.connect(self.openresyltati)
        self.pushButtontomain.clicked.connect(self.returnToMain)

    def openresyltati(self):
        rows = self.cursor.fetchall()
        for row in rows:                                           
            id, fio, grup, rez = row.values()                        
            if fio and grup and rez:                                
                self.textEdit.append(                                 
                    f'{id:>3} | {fio:>40} | {grup:>10} | {rez:>3}'     
                ) 

    def returnToMain(self):
        self.close()
        w.show()

class TestWindow(QtWidgets.QMainWindow, Ui_Test):
    def __init__(self):
        super(TestWindow, self).__init__()
        self.setupUi(self)
        self.connection = sqlite3.connect( 'diplom.db')
        self.cursor = self.connection.cursor()

        self.pushButtonEndTest.clicked.connect(self.Resylt)

    def Resylt(self):
        self.res = 0
        if self.comboBox.currentIndex() == self.kk_1:
            self.res = self.res+1
        if self.comboBox_2.currentIndex() == self.kk_2:
            self.res = self.res+1
        if self.comboBox_3.currentIndex() == self.kk_3:
                self.res = self.res+1
        if self.comboBox_4.currentIndex() == self.kk_4:
                self.res = self.res+1
        if self.comboBox_5.currentIndex() == self.kk_5:
                self.res = self.res+1
        print("Количество верных ответов - " + str(self.res))
        self.cursor.execute(f"UPDATE students SET Результат = '{self.res}' ORDER BY id DESC LIMIT 1")
        self.connection.commit()





class LoginWindow(QtWidgets.QMainWindow, Ui_Login):
    def __init__(self, connection):
        super(LoginWindow, self).__init__()
        self.setupUi(self)
        self.connection = sqlite3.connect( 'diplom.db')
        self.cursor = self.connection.cursor()
        
        self.pushButton.clicked.connect(self.check_password)
        self.pushButton.clicked.connect(self.testImage)
        self.pushButton.clicked.connect(self.testText)
        

    def opentest(self):
        self.fio = self.lineEdit_2.text()
        self.grupp = self.lineEdit_3.text()
        self.cursor = self.connection.cursor()
        self.cursor.execute(f"INSERT INTO students (ФИО, Номер_группы) VALUES ('{self.fio}', '{self.grupp}')")
        self.connection.commit()

        self.test = TestWindow()

        self.close()
        self.test.show()

    def check_password(self):
            self.fio = self.lineEdit_2.text()
            self.grupp = self.lineEdit_3.text()
            if not self.fio or not self.grupp:    
                msg = QMessageBox.information(
                    self, 
                    'Внимание', 
                    'Введите данные для авторизации.'
                )
                return            
            elif self.fio != self.lineEdit_2.text() or self.grupp != self.lineEdit_3.text():    
                msg = QMessageBox.information(
                    self, 
                )              
                return     

            self.opentest()     

    
    def testImage(self):
        mas = random.sample(range(1, 9), 2)
        a = mas[0]
        b = mas[1]

        print(a, b)

        a1 = "SELECT VoprosImage FROM diplom.test WHERE id =" + str(a) + ";"
        b1 = "SELECT VoprosImage FROM diplom.test WHERE id =" + str(b) + ";"

        a11 = "SELECT VoprosText FROM diplom.test WHERE id =" + str(a) + ";"
        b11 = "SELECT VoprosText FROM diplom.test WHERE id =" + str(b) + ";"
        

        mas1 = random.sample(range(1, 5), 4)
        k_1 = mas1[0]
        l_1 = mas1[1]
        m_1 = mas1[2]
        n_1 = mas1[3]
        print(k_1)
        self.test.kk_1 = mas1[0]

        mas2 = random.sample(range(1, 5), 4)
        k_2 = mas2[0]
        l_2 = mas2[1]
        m_2 = mas2[2]
        n_2 = mas2[3]
        print(k_2, l_2, m_2, n_2)
        self.test.kk_2 = mas2[0]

        k1 = "SELECT otv1 FROM diplom.test WHERE id =" + str(a) + ";"
        l1 = "SELECT otv2 FROM diplom.test WHERE id =" + str(a) + ";"
        m1 = "SELECT otv3 FROM diplom.test WHERE id =" + str(a) + ";"
        n1 = "SELECT otv4 FROM diplom.test WHERE id =" + str(a) + ";"

        k2 = "SELECT otv1 FROM diplom.test WHERE id =" + str(b) + ";"
        l2 = "SELECT otv2 FROM diplom.test WHERE id =" + str(b) + ";"
        m2 = "SELECT otv3 FROM diplom.test WHERE id =" + str(b) + ";"
        n2 = "SELECT otv4 FROM diplom.test WHERE id =" + str(b) + ";"


        with self.connection.cursor() as cursor:
            cursor.execute(a1)
            result = cursor.fetchone()
            a2 = result['VoprosImage']
            pix = QPixmap()                                           
            rez = pix.loadFromData(a2)                              
            print(f'rez = {rez}\n') 
            self.test.label_2.setPixmap(pix)                              

            cursor.execute(b1)
            result = cursor.fetchone()
            b2 = result['VoprosImage']
            pix = QPixmap()                                      
            rez = pix.loadFromData(b2)                             
            print(f'rez = {rez}\n') 
            self.test.label_4.setPixmap(pix) 

            cursor.execute(a11)
            result = cursor.fetchone()
            a22 = result['VoprosText']
            self.test.textEdit_4.setText(str(a22))
            
            cursor.execute(b11)
            result = cursor.fetchone()
            b22 = result['VoprosText']
            self.test.textEdit_5.setText(str(b22))

            self.test.comboBox.addItem(""); self.test.comboBox.addItem(""); self.test.comboBox.addItem(""); self.test.comboBox.addItem("")
            self.test.comboBox_2.addItem(""); self.test.comboBox_2.addItem(""); self.test.comboBox_2.addItem(""); self.test.comboBox_2.addItem("")
        
        #Вопрос 1
            cursor.execute(k1)
            result = cursor.fetchone()
            kk1 = result['otv1']
            self.test.comboBox.setItemText(k_1, str(kk1))

            cursor.execute(l1)
            result = cursor.fetchone()
            ll1 = result['otv2']
            self.test.comboBox.setItemText(l_1, str(ll1))

            cursor.execute(m1)
            result = cursor.fetchone()
            mm1 = result['otv3']
            self.test.comboBox.setItemText(m_1, str(mm1))

            cursor.execute(n1)
            result = cursor.fetchone()
            nn1 = result['otv4']
            self.test.comboBox.setItemText(n_1, str(nn1))

        #Вопрос 2
            cursor.execute(k2)
            result = cursor.fetchone()
            kk2 = result['otv1']
            self.test.comboBox_2.setItemText(k_2, str(kk2))

            cursor.execute(l2)
            result = cursor.fetchone()
            ll2 = result['otv2']
            self.test.comboBox_2.setItemText(l_2, str(ll2))

            cursor.execute(m2)
            result = cursor.fetchone()
            mm2 = result['otv3']
            self.test.comboBox_2.setItemText(m_2, str(mm2))

            cursor.execute(n2)
            result = cursor.fetchone()
            nn2 = result['otv4']
            self.test.comboBox_2.setItemText(n_2, str(nn2))

    def testText(self):
        mas = random.sample(range(9, 21), 3)
        c = mas[0]
        d = mas[1]
        e = mas[2]
        print(c, d, e)
    
        c1 = "SELECT VoprosText FROM diplom.test WHERE id =" + str(c) + ";"
        d1 = "SELECT VoprosText FROM diplom.test WHERE id =" + str(d) + ";"
        e1 = "SELECT VoprosText FROM diplom.test WHERE id =" + str(e) + ";"
        
        mas3 = random.sample(range(1, 5), 4)
        k_3 = mas3[0]
        l_3 = mas3[1]
        m_3 = mas3[2]
        n_3 = mas3[3]
        print(k_3)
        self.test.kk_3 = mas3[0]

        mas4 = random.sample(range(1, 5), 4)
        k_4 = mas4[0]
        l_4 = mas4[1]
        m_4 = mas4[2]
        n_4 = mas4[3]
        print(k_4)
        self.test.kk_4 = mas4[0]

        mas5 = random.sample(range(1, 5), 4)
        k_5 = mas5[0]
        l_5 = mas5[1]
        m_5 = mas5[2]
        n_5 = mas5[3]
        print(k_5)
        self.test.kk_5 = mas5[0]

        k3 = "SELECT otv1 FROM diplom.test WHERE id =" + str(c) + ";"
        l3 = "SELECT otv2 FROM diplom.test WHERE id =" + str(c) + ";"
        m3 = "SELECT otv3 FROM diplom.test WHERE id =" + str(c) + ";"
        n3 = "SELECT otv4 FROM diplom.test WHERE id =" + str(c) + ";"

        k4 = "SELECT otv1 FROM diplom.test WHERE id =" + str(d) + ";"
        l4 = "SELECT otv2 FROM diplom.test WHERE id =" + str(d) + ";"
        m4 = "SELECT otv3 FROM diplom.test WHERE id =" + str(d) + ";"
        n4 = "SELECT otv4 FROM diplom.test WHERE id =" + str(d) + ";"
        
        k5 = "SELECT otv1 FROM diplom.test WHERE  id =" + str(e) + ";"
        l5 = "SELECT otv2 FROM diplom.test WHERE  id =" + str(e) + ";"
        m5 = "SELECT otv3 FROM diplom.test WHERE  id =" + str(e) + ";"
        n5 = "SELECT otv4 FROM diplom.test WHERE  id =" + str(e) + ";"

        with self.connection.cursor() as cursor:
            cursor.execute(c1)
            result = cursor.fetchone()
            c2 = result['VoprosText']
            self.test.textEdit.setText(str(c2))

            cursor.execute(d1)
            result = cursor.fetchone()
            d2 = result['VoprosText']
            self.test.textEdit_2.setText(str(d2))

            cursor.execute(e1)
            result = cursor.fetchone()
            e2 = result['VoprosText']
            self.test.textEdit_3.setText(str(e2))

            self.test.comboBox_3.addItem(""); self.test.comboBox_3.addItem(""); self.test.comboBox_3.addItem(""); self.test.comboBox_3.addItem("")
            self.test.comboBox_4.addItem(""); self.test.comboBox_4.addItem(""); self.test.comboBox_4.addItem(""); self.test.comboBox_4.addItem("")
            self.test.comboBox_5.addItem(""); self.test.comboBox_5.addItem(""); self.test.comboBox_5.addItem(""); self.test.comboBox_5.addItem("")
        
        #Вопрос 1
            cursor.execute(k3)
            result = cursor.fetchone()
            kk3 = result['otv1']
            self.test.comboBox_3.setItemText(k_3, str(kk3))

            cursor.execute(l3)
            result = cursor.fetchone()
            ll3 = result['otv2']
            self.test.comboBox_3.setItemText(l_3, str(ll3))

            cursor.execute(m3)
            result = cursor.fetchone()
            mm3 = result['otv3']
            self.test.comboBox_3.setItemText(m_3, str(mm3))

            cursor.execute(n3)
            result = cursor.fetchone()
            nn3 = result['otv4']
            self.test.comboBox_3.setItemText(n_3, str(nn3))

        #Вопрос 2
            cursor.execute(k4)
            result = cursor.fetchone()
            kk4 = result['otv1']
            self.test.comboBox_4.setItemText(k_4, str(kk4))

            cursor.execute(l4)
            result = cursor.fetchone()
            ll4 = result['otv2']
            self.test.comboBox_4.setItemText(l_4, str(ll4))

            cursor.execute(m4)
            result = cursor.fetchone()
            mm4 = result['otv3']
            self.test.comboBox_4.setItemText(m_4, str(mm4))

            cursor.execute(n4)
            result = cursor.fetchone()
            nn4 = result['otv4']
            self.test.comboBox_4.setItemText(n_4, str(nn4))

        #Вопрос 3
            cursor.execute(k5)
            result = cursor.fetchone()
            kk5 = result['otv1']
            self.test.comboBox_5.setItemText(k_5, str(kk5))

            cursor.execute(l5)
            result = cursor.fetchone()
            ll5 = result['otv2']
            self.test.comboBox_5.setItemText(l_5, str(ll5))

            cursor.execute(m5)
            result = cursor.fetchone()
            mm5 = result['otv3']
            self.test.comboBox_5.setItemText(m_5, str(mm5))

            cursor.execute(n5)
            result = cursor.fetchone()
            nn5 = result['otv4']
            self.test.comboBox_5.setItemText(n_5, str(nn5))
    

if __name__ == "__main__":

    app = QtWidgets.QApplication(sys.argv)
    w = MainWindow()
    w.show()
    sys.exit(app.exec_())
  

titul.py


from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_mainWindow(object):
    def setupUi(self, mainWindow):
        mainWindow.setObjectName("mainWindow")
        mainWindow.resize(1100, 800)
        mainWindow.setStyleSheet("background-color: rgb(255, 255, 255);")
        mainWindow.setAnimated(True)
        self.centralwidget = QtWidgets.QWidget(mainWindow)
        self.centralwidget.setAutoFillBackground(False)
        self.centralwidget.setObjectName("centralwidget")
        self.Button_runLR = QtWidgets.QPushButton(self.centralwidget)
        self.Button_runLR.setGeometry(QtCore.QRect(400, 310, 271, 81))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.Button_runLR.setFont(font)
        self.Button_runLR.setStyleSheet("background-color: rgb(227, 210, 255);")
        self.Button_runLR.setObjectName("Button_runLR")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(0, 0, 1101, 801))
        self.label.setText("")
        self.label.setPixmap(QtGui.QPixmap("images.jpg"))
        self.label.setScaledContents(True)
        self.label.setObjectName("label")
        self.Button_startTest = QtWidgets.QPushButton(self.centralwidget)
        self.Button_startTest.setGeometry(QtCore.QRect(400, 530, 271, 81))
        font = QtGui.QFont()
        font.setFamily("Tahoma")
        font.setPointSize(14)
        self.Button_startTest.setFont(font)
        self.Button_startTest.setStyleSheet("background-color: rgb(227, 210, 255);")
        self.Button_startTest.setObjectName("Button_startTest")
        self.Button_Rezylt = QtWidgets.QPushButton(self.centralwidget)
        self.Button_Rezylt.setGeometry(QtCore.QRect(400, 420, 271, 81))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.Button_Rezylt.setFont(font)
        self.Button_Rezylt.setStyleSheet("background-color: rgb(227, 210, 255);")
        self.Button_Rezylt.setObjectName("Button_Rezylt")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(350, 100, 381, 51))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.label_2.setFont(font)
        self.label_2.setStyleSheet("background-color: rgb(227, 210, 255);")
        self.label_2.setObjectName("label_2")
        self.label.raise_()
        self.Button_runLR.raise_()
        self.Button_startTest.raise_()
        self.Button_Rezylt.raise_()
        self.label_2.raise_()
        mainWindow.setCentralWidget(self.centralwidget)

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

    def retranslateUi(self, mainWindow):
        _translate = QtCore.QCoreApplication.translate
        mainWindow.setWindowTitle(_translate("mainWindow", "Главная"))
        self.Button_runLR.setText(_translate("mainWindow", "Начать лабораторную \n"
"работу"))
        self.Button_startTest.setText(_translate("mainWindow", "Начать тест"))
        self.Button_Rezylt.setText(_translate("mainWindow", "Посмотреть результаты"))
        self.label_2.setText(_translate("mainWindow", "Изучение этапов преобразования биосигналов"))

login.py


from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Login(object):
    def setupUi(self, Login):
        Login.setObjectName("Login")
        Login.resize(1100, 800)
        Login.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.centralwidget = QtWidgets.QWidget(Login)
        self.centralwidget.setObjectName("centralwidget")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(280, 120, 581, 41))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
        self.label.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.label.setFont(font)
        self.label.setStyleSheet("background-color: rgb(198, 212, 255);")
        self.label.setObjectName("label")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(490, 440, 141, 71))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
        self.pushButton.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.pushButton.setFont(font)
        self.pushButton.setStyleSheet("background-color: rgb(198, 212, 255);")
        self.pushButton.setObjectName("pushButton")
        self.label_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(480, 310, 141, 31))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.label_3.sizePolicy().hasHeightForWidth())
        self.label_3.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.label_3.setFont(font)
        self.label_3.setStyleSheet("background-color: rgb(198, 212, 255);")
        self.label_3.setObjectName("label_3")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(520, 190, 61, 41))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.label_2.sizePolicy().hasHeightForWidth())
        self.label_2.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.label_2.setFont(font)
        self.label_2.setStyleSheet("background-color: rgb(198, 212, 255);")
        self.label_2.setObjectName("label_2")
        self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit_2.setGeometry(QtCore.QRect(380, 260, 331, 31))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.lineEdit_2.sizePolicy().hasHeightForWidth())
        self.lineEdit_2.setSizePolicy(sizePolicy)
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.lineEdit_3 = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit_3.setGeometry(QtCore.QRect(380, 360, 331, 31))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.lineEdit_3.sizePolicy().hasHeightForWidth())
        self.lineEdit_3.setSizePolicy(sizePolicy)
        self.lineEdit_3.setObjectName("lineEdit_3")
        self.label_4 = QtWidgets.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(-4, -8, 1111, 811))
        self.label_4.setAutoFillBackground(False)
        self.label_4.setText("")
        self.label_4.setPixmap(QtGui.QPixmap("images2.jpg"))
        self.label_4.setScaledContents(True)
        self.label_4.setObjectName("label_4")
        self.label_4.raise_()
        self.label.raise_()
        self.pushButton.raise_()
        self.label_3.raise_()
        self.label_2.raise_()
        self.lineEdit_2.raise_()
        self.lineEdit_3.raise_()
        Login.setCentralWidget(self.centralwidget)

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

    def retranslateUi(self, Login):
        _translate = QtCore.QCoreApplication.translate
        Login.setWindowTitle(_translate("Login", "Авторизация"))
        self.label.setText(_translate("Login", "<html><head/><body><p align=\"center\"><span style=\" font-size:14pt;\">Для прохождения теста необходимо заполнить ФИО и номер группы</span></p></body></html>"))
        self.pushButton.setText(_translate("Login", "Продолжить"))
        self.label_3.setText(_translate("Login", "<html><head/><body><p align=\"center\"><span style=\" font-size:14pt;\">Номер группы</span></p></body></html>"))
        self.label_2.setText(_translate("Login", "<html><head/><body><p align=\"center\"><span style=\" font-size:14pt;\">ФИО</span></p></body></html>"))

test.py

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Test(object):
    def setupUi(self, Test):
        Test.setObjectName("Test")
        Test.resize(1100, 800)
        Test.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.centralwidget = QtWidgets.QWidget(Test)
        self.centralwidget.setObjectName("centralwidget")
        self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
        self.tabWidget.setGeometry(QtCore.QRect(0, 0, 1111, 761))
        self.tabWidget.setObjectName("tabWidget")
        self.tab = QtWidgets.QWidget()
        self.tab.setObjectName("tab")
        self.label = QtWidgets.QLabel(self.tab)
        self.label.setGeometry(QtCore.QRect(20, 0, 81, 16))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.label.setFont(font)
        self.label.setObjectName("label")
        self.comboBox = QtWidgets.QComboBox(self.tab)
        self.comboBox.setGeometry(QtCore.QRect(10, 310, 621, 22))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.comboBox.setFont(font)
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.label_2 = QtWidgets.QLabel(self.tab)
        self.label_2.setGeometry(QtCore.QRect(10, 60, 621, 241))
        self.label_2.setText("")
        self.label_2.setScaledContents(True)
        self.label_2.setObjectName("label_2")
        self.label_4 = QtWidgets.QLabel(self.tab)
        self.label_4.setGeometry(QtCore.QRect(10, 430, 611, 281))
        self.label_4.setText("")
        self.label_4.setScaledContents(True)
        self.label_4.setObjectName("label_4")
        self.label_3 = QtWidgets.QLabel(self.tab)
        self.label_3.setGeometry(QtCore.QRect(20, 350, 81, 16))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.label_3.setFont(font)
        self.label_3.setObjectName("label_3")
        self.comboBox_2 = QtWidgets.QComboBox(self.tab)
        self.comboBox_2.setGeometry(QtCore.QRect(10, 710, 631, 22))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.comboBox_2.setFont(font)
        self.comboBox_2.setObjectName("comboBox_2")
        self.comboBox_2.addItem("")
        self.textEdit_4 = QtWidgets.QTextEdit(self.tab)
        self.textEdit_4.setGeometry(QtCore.QRect(10, 20, 1081, 41))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.textEdit_4.setFont(font)
        self.textEdit_4.setObjectName("textEdit_4")
        self.textEdit_5 = QtWidgets.QTextEdit(self.tab)
        self.textEdit_5.setGeometry(QtCore.QRect(10, 380, 1081, 41))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.textEdit_5.setFont(font)
        self.textEdit_5.setObjectName("textEdit_5")
        self.tabWidget.addTab(self.tab, "")
        self.tab_2 = QtWidgets.QWidget()
        self.tab_2.setObjectName("tab_2")
        self.comboBox_3 = QtWidgets.QComboBox(self.tab_2)
        self.comboBox_3.setGeometry(QtCore.QRect(20, 150, 971, 22))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.comboBox_3.setFont(font)
        self.comboBox_3.setObjectName("comboBox_3")
        self.comboBox_3.addItem("")
        self.label_6 = QtWidgets.QLabel(self.tab_2)
        self.label_6.setGeometry(QtCore.QRect(20, 10, 81, 16))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.label_6.setFont(font)
        self.label_6.setObjectName("label_6")
        self.comboBox_4 = QtWidgets.QComboBox(self.tab_2)
        self.comboBox_4.setGeometry(QtCore.QRect(20, 330, 971, 22))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.comboBox_4.setFont(font)
        self.comboBox_4.setObjectName("comboBox_4")
        self.comboBox_4.addItem("")
        self.label_7 = QtWidgets.QLabel(self.tab_2)
        self.label_7.setGeometry(QtCore.QRect(20, 190, 81, 16))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.label_7.setFont(font)
        self.label_7.setObjectName("label_7")
        self.comboBox_5 = QtWidgets.QComboBox(self.tab_2)
        self.comboBox_5.setGeometry(QtCore.QRect(20, 530, 971, 22))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.comboBox_5.setFont(font)
        self.comboBox_5.setObjectName("comboBox_5")
        self.comboBox_5.addItem("")
        self.label_8 = QtWidgets.QLabel(self.tab_2)
        self.label_8.setGeometry(QtCore.QRect(20, 390, 81, 16))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.label_8.setFont(font)
        self.label_8.setObjectName("label_8")
        self.textEdit = QtWidgets.QTextEdit(self.tab_2)
        self.textEdit.setGeometry(QtCore.QRect(20, 30, 971, 121))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.textEdit.setFont(font)
        self.textEdit.setObjectName("textEdit")
        self.textEdit_2 = QtWidgets.QTextEdit(self.tab_2)
        self.textEdit_2.setGeometry(QtCore.QRect(20, 210, 971, 121))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.textEdit_2.setFont(font)
        self.textEdit_2.setObjectName("textEdit_2")
        self.textEdit_3 = QtWidgets.QTextEdit(self.tab_2)
        self.textEdit_3.setGeometry(QtCore.QRect(20, 410, 971, 121))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.textEdit_3.setFont(font)
        self.textEdit_3.setObjectName("textEdit_3")
        self.tabWidget.addTab(self.tab_2, "")
        self.pushButtonEndTest = QtWidgets.QPushButton(self.centralwidget)
        self.pushButtonEndTest.setGeometry(QtCore.QRect(880, 760, 211, 31))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.pushButtonEndTest.setFont(font)
        self.pushButtonEndTest.setStyleSheet("background-color: rgb(212, 212, 212);")
        self.pushButtonEndTest.setObjectName("pushButtonEndTest")
        Test.setCentralWidget(self.centralwidget)

        self.retranslateUi(Test)
        self.tabWidget.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(Test)

    def retranslateUi(self, Test):
        _translate = QtCore.QCoreApplication.translate
        Test.setWindowTitle(_translate("Test", "Тест"))
        self.label.setText(_translate("Test", "Вопрос 1"))
        self.comboBox.setItemText(0, _translate("Test", "..."))
        self.label_3.setText(_translate("Test", "Вопрос 2"))
        self.comboBox_2.setItemText(0, _translate("Test", "..."))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("Test", "Вопросы с картинкой"))
        self.comboBox_3.setItemText(0, _translate("Test", "..."))
        self.label_6.setText(_translate("Test", "Вопрос 3"))
        self.comboBox_4.setItemText(0, _translate("Test", "..."))
        self.label_7.setText(_translate("Test", "Вопрос 4"))
        self.comboBox_5.setItemText(0, _translate("Test", "..."))
        self.label_8.setText(_translate("Test", "Вопрос 5"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("Test", "Текстовые вопросы"))
        self.pushButtonEndTest.setText(_translate("Test", "Закончить тест"))

введите сюда описание изображения

Источник: https://ru.stackoverflow.com/questions/1425222/%D0%9E%D1%88%D0%B8%D0%B1%D0%BA%D0%B0-attributeerror-enter

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

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