1

Хочу реализовать так, чтобы при выборе правильного варианта выпадающего списка, цвет шрифта или цвет заднего фона (не знаю, что из этого реализуемо, а что нет) менялся на любой другой цвет, но как это сделать не знаю.

Как это можно сделать?

Код:

from PyQt5 import QtCore, QtGui, QtWidgets 


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(732, 570)
        MainWindow.setDocumentMode(True)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(20, 20, 421, 81))
        self.label_2.setScaledContents(True)
        self.label_2.setWordWrap(True)
        self.label_2.setOpenExternalLinks(False)
        self.label_2.setObjectName("label_2")
        self.AnswerEdit = QtWidgets.QLineEdit(self.centralwidget)
        self.AnswerEdit.setGeometry(QtCore.QRect(150, 50, 101, 16))
        self.AnswerEdit.setObjectName("AnswerEdit")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(20, 100, 401, 51))
        self.label.setWordWrap(True)
        self.label.setObjectName("label")
        self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit_2.setGeometry(QtCore.QRect(120, 110, 101, 16))
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.label_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(20, 170, 411, 61))
        self.label_3.setObjectName("label_3")
        self.AnswerBox = QtWidgets.QComboBox(self.centralwidget)
        self.AnswerBox.setGeometry(QtCore.QRect(320, 190, 121, 22))
        self.AnswerBox.setStyleSheet("")
        self.AnswerBox.setObjectName("AnswerBox")
        self.AnswerBox.addItem("")
        self.AnswerBox.addItem("")
        self.AnswerBox.addItem("")
        self.AnswerBox.addItem("")
        self.CheckButton = QtWidgets.QPushButton(self.centralwidget)
        self.CheckButton.setGeometry(QtCore.QRect(500, 60, 121, 31))
        self.CheckButton.setObjectName("CheckButton")
        self.comboBox_1_1 = QtWidgets.QComboBox(self.centralwidget)
        self.comboBox_1_1.setGeometry(QtCore.QRect(20, 260, 111, 22))
        self.comboBox_1_1.setObjectName("comboBox_1_1")
        self.comboBox_1_1.addItem("")
        self.comboBox_1_1.addItem("")
        self.comboBox_1_1.addItem("")
        self.comboBox_1_3 = QtWidgets.QComboBox(self.centralwidget)
        self.comboBox_1_3.setGeometry(QtCore.QRect(20, 340, 111, 22))
        self.comboBox_1_3.setObjectName("comboBox_1_3")
        self.comboBox_1_3.addItem("")
        self.comboBox_1_3.addItem("")
        self.comboBox_1_3.addItem("")
        self.comboBox_1_2 = QtWidgets.QComboBox(self.centralwidget)
        self.comboBox_1_2.setGeometry(QtCore.QRect(20, 300, 111, 22))
        self.comboBox_1_2.setObjectName("comboBox_1_2")
        self.comboBox_1_2.addItem("")
        self.comboBox_1_2.addItem("")
        self.comboBox_1_2.addItem("")
        self.label_4 = QtWidgets.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(160, 260, 91, 21))
        self.label_4.setObjectName("label_4")
        self.label_5 = QtWidgets.QLabel(self.centralwidget)
        self.label_5.setGeometry(QtCore.QRect(160, 300, 91, 21))
        self.label_5.setObjectName("label_5")
        self.label_6 = QtWidgets.QLabel(self.centralwidget)
        self.label_6.setGeometry(QtCore.QRect(160, 340, 121, 21))
        self.label_6.setObjectName("label_6")
        self.AnswerLabel_2 = QtWidgets.QLabel(self.centralwidget)
        self.AnswerLabel_2.setGeometry(QtCore.QRect(290, 290, 81, 21))
        self.AnswerLabel_2.setObjectName("AnswerLabel_2")
        self.CheckButton_2 = QtWidgets.QPushButton(self.centralwidget)
        self.CheckButton_2.setGeometry(QtCore.QRect(50, 390, 111, 31))
        self.CheckButton_2.setObjectName("CheckButton_2")
        self.AnswerLabel = QtWidgets.QLabel(self.centralwidget)
        self.AnswerLabel.setGeometry(QtCore.QRect(520, 110, 91, 21))
        self.AnswerLabel.setObjectName("AnswerLabel")
        self.WordBox_1_1 = QtWidgets.QComboBox(self.centralwidget)
        self.WordBox_1_1.setGeometry(QtCore.QRect(390, 260, 111, 22))
        self.WordBox_1_1.setObjectName("WordBox_1_1")
        self.WordBox_1_1.addItem("")
        self.WordBox_1_1.addItem("")
        self.WordBox_1_1.addItem("")
        self.DescBox_1_1 = QtWidgets.QComboBox(self.centralwidget)
        self.DescBox_1_1.setGeometry(QtCore.QRect(530, 260, 111, 22))
        self.DescBox_1_1.setObjectName("DescBox_1_1")
        self.DescBox_1_1.addItem("")
        self.DescBox_1_1.addItem("")
        self.DescBox_1_1.addItem("")
        self.AnswerLabel_3 = QtWidgets.QLabel(self.centralwidget)
        self.AnswerLabel_3.setGeometry(QtCore.QRect(650, 290, 61, 21))
        self.AnswerLabel_3.setObjectName("AnswerLabel_3")
        self.CheckButton_3 = QtWidgets.QPushButton(self.centralwidget)
        self.CheckButton_3.setGeometry(QtCore.QRect(430, 390, 111, 31))
        self.CheckButton_3.setObjectName("CheckButton_3")
        self.WordBox_1_2 = QtWidgets.QComboBox(self.centralwidget)
        self.WordBox_1_2.setGeometry(QtCore.QRect(390, 290, 111, 22))
        self.WordBox_1_2.setObjectName("WordBox_1_2")
        self.WordBox_1_2.addItem("")
        self.WordBox_1_2.addItem("")
        self.WordBox_1_2.addItem("")
        self.WordBox_1_3 = QtWidgets.QComboBox(self.centralwidget)
        self.WordBox_1_3.setGeometry(QtCore.QRect(390, 320, 111, 22))
        self.WordBox_1_3.setObjectName("WordBox_1_3")
        self.WordBox_1_3.addItem("")
        self.WordBox_1_3.addItem("")
        self.WordBox_1_3.addItem("")
        self.DescBox_1_3 = QtWidgets.QComboBox(self.centralwidget)
        self.DescBox_1_3.setGeometry(QtCore.QRect(530, 320, 111, 22))
        self.DescBox_1_3.setObjectName("DescBox_1_3")
        self.DescBox_1_3.addItem("")
        self.DescBox_1_3.addItem("")
        self.DescBox_1_3.addItem("")
        self.DescBox_1_2 = QtWidgets.QComboBox(self.centralwidget)
        self.DescBox_1_2.setGeometry(QtCore.QRect(530, 290, 111, 22))
        self.DescBox_1_2.setObjectName("DescBox_1_2")
        self.DescBox_1_2.addItem("")
        self.DescBox_1_2.addItem("")
        self.DescBox_1_2.addItem("")
        self.CheckButton_4 = QtWidgets.QPushButton(self.centralwidget)
        self.CheckButton_4.setGeometry(QtCore.QRect(480, 190, 81, 23))
        self.CheckButton_4.setObjectName("CheckButton_4")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 732, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

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

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.label_2.setText(_translate("MainWindow", "This is a test text. It\'s main                                    is to understand what can i do and how it is possible to create"))
        self.label.setText(_translate("MainWindow", "This programm is so                                     (progress) and gives me a lot of abillities and it is awesome"))
        self.label_3.setText(_translate("MainWindow", "There are two versions of this programms and they are really "))
        self.AnswerBox.setItemText(0, _translate("MainWindow", "Choose a word"))
        self.AnswerBox.setItemText(1, _translate("MainWindow", "difference"))
        self.AnswerBox.setItemText(2, _translate("MainWindow", "different"))
        self.AnswerBox.setItemText(3, _translate("MainWindow", "indifferent"))
        self.CheckButton.setText(_translate("MainWindow", "Check"))
        self.comboBox_1_1.setItemText(0, _translate("MainWindow", "Car"))
        self.comboBox_1_1.setItemText(1, _translate("MainWindow", "Plane"))
        self.comboBox_1_1.setItemText(2, _translate("MainWindow", "Boat"))
        self.comboBox_1_3.setItemText(0, _translate("MainWindow", "Car"))
        self.comboBox_1_3.setItemText(1, _translate("MainWindow", "Plane"))
        self.comboBox_1_3.setItemText(2, _translate("MainWindow", "Boat"))
        self.comboBox_1_2.setItemText(0, _translate("MainWindow", "Car"))
        self.comboBox_1_2.setItemText(1, _translate("MainWindow", "Plane"))
        self.comboBox_1_2.setItemText(2, _translate("MainWindow", "Boat"))
        self.label_4.setText(_translate("MainWindow", "moves in the air"))
        self.label_5.setText(_translate("MainWindow", "goes on the road"))
        self.label_6.setText(_translate("MainWindow", "moves on the water"))
        self.AnswerLabel_2.setText(_translate("MainWindow", "TextLabel"))
        self.CheckButton_2.setText(_translate("MainWindow", "Check"))
        self.AnswerLabel.setText(_translate("MainWindow", "TextLabel"))
        self.WordBox_1_1.setItemText(0, _translate("MainWindow", "Car"))
        self.WordBox_1_1.setItemText(1, _translate("MainWindow", "Plane"))
        self.WordBox_1_1.setItemText(2, _translate("MainWindow", "Boat"))
        self.DescBox_1_1.setItemText(0, _translate("MainWindow", "moves on the road"))
        self.DescBox_1_1.setItemText(1, _translate("MainWindow", "moves on the water"))
        self.DescBox_1_1.setItemText(2, _translate("MainWindow", "moves in the air"))
        self.AnswerLabel_3.setText(_translate("MainWindow", "TextLabel"))
        self.CheckButton_3.setText(_translate("MainWindow", "Check"))
        self.WordBox_1_2.setItemText(0, _translate("MainWindow", "Car"))
        self.WordBox_1_2.setItemText(1, _translate("MainWindow", "Plane"))
        self.WordBox_1_2.setItemText(2, _translate("MainWindow", "Boat"))
        self.WordBox_1_3.setItemText(0, _translate("MainWindow", "Car"))
        self.WordBox_1_3.setItemText(1, _translate("MainWindow", "Plane"))
        self.WordBox_1_3.setItemText(2, _translate("MainWindow", "Boat"))
        self.DescBox_1_3.setItemText(0, _translate("MainWindow", "moves on the road"))
        self.DescBox_1_3.setItemText(1, _translate("MainWindow", "moves on the water"))
        self.DescBox_1_3.setItemText(2, _translate("MainWindow", "moves in the air"))
        self.DescBox_1_2.setItemText(0, _translate("MainWindow", "moves on the road"))
        self.DescBox_1_2.setItemText(1, _translate("MainWindow", "moves on the water"))
        self.DescBox_1_2.setItemText(2, _translate("MainWindow", "moves in the air"))
        self.CheckButton_4.setText(_translate("MainWindow", "Check"))

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

        self.setupUi(self)


        self.CheckButton.clicked.connect(self.checkanswer1)
        self.CheckButton_2.clicked.connect(self.checkanswer2)
        

        self.a = " "
        self.b = " "




    def setanswer1(self):
        self.a = self.AnswerEdit.text()
        self.b = self.lineEdit_2.text()

    def checkanswer1(self):
        self.setanswer1()
        
        if str(self.a) == "aim":
            self.AnswerEdit.setStyleSheet("QLineEdit { color : green}")
        elif str(self.a) == "":
            pass
        else:
            self.AnswerEdit.setStyleSheet("QLineEdit { color : red}")

        if str(self.b) == "progressive" :
            self.lineEdit_2.setStyleSheet("QLineEdit { color : green}")
        elif str(self.b) == "" :
            pass
        else:
            self.lineEdit_2.setStyleSheet("QLineEdit { color : red}")


        

    def checkanswer2(self):

        if self.comboBox_1_1.currentText() == "Car":
            self.AnswerLabel_2.setText('good job')
        else:
            self.AnswerLabel_2.setText("Try again")




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

1 ответ 1

2

Попробуйте так:

from PyQt5 import QtCore, QtGui, QtWidgets 


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(732, 570)
        MainWindow.setDocumentMode(True)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(20, 20, 421, 81))
        self.label_2.setScaledContents(True)
        self.label_2.setWordWrap(True)
        self.label_2.setOpenExternalLinks(False)
        self.label_2.setObjectName("label_2")
        self.AnswerEdit = QtWidgets.QLineEdit(self.centralwidget)
        self.AnswerEdit.setGeometry(QtCore.QRect(150, 50, 101, 16))
        self.AnswerEdit.setObjectName("AnswerEdit")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(20, 100, 401, 51))
        self.label.setWordWrap(True)
        self.label.setObjectName("label")
        self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit_2.setGeometry(QtCore.QRect(120, 110, 101, 16))
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.label_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(20, 170, 411, 61))
        self.label_3.setObjectName("label_3")
        self.AnswerBox = QtWidgets.QComboBox(self.centralwidget)
        self.AnswerBox.setGeometry(QtCore.QRect(320, 190, 121, 22))
        self.AnswerBox.setStyleSheet("")
        self.AnswerBox.setObjectName("AnswerBox")
        self.AnswerBox.addItem("")
        self.AnswerBox.addItem("")
        self.AnswerBox.addItem("")
        self.AnswerBox.addItem("")
        self.CheckButton = QtWidgets.QPushButton(self.centralwidget)
        self.CheckButton.setGeometry(QtCore.QRect(500, 60, 121, 31))
        self.CheckButton.setObjectName("CheckButton")
        self.comboBox_1_1 = QtWidgets.QComboBox(self.centralwidget)
        self.comboBox_1_1.setGeometry(QtCore.QRect(20, 260, 111, 22))
        self.comboBox_1_1.setObjectName("comboBox_1_1")
        self.comboBox_1_1.addItem("")
        self.comboBox_1_1.addItem("")
        self.comboBox_1_1.addItem("")
        self.comboBox_1_3 = QtWidgets.QComboBox(self.centralwidget)
        self.comboBox_1_3.setGeometry(QtCore.QRect(20, 340, 111, 22))
        self.comboBox_1_3.setObjectName("comboBox_1_3")
        self.comboBox_1_3.addItem("")
        self.comboBox_1_3.addItem("")
        self.comboBox_1_3.addItem("")
        self.comboBox_1_2 = QtWidgets.QComboBox(self.centralwidget)
        self.comboBox_1_2.setGeometry(QtCore.QRect(20, 300, 111, 22))
        self.comboBox_1_2.setObjectName("comboBox_1_2")
        self.comboBox_1_2.addItem("")
        self.comboBox_1_2.addItem("")
        self.comboBox_1_2.addItem("")
        self.label_4 = QtWidgets.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(160, 260, 91, 21))
        self.label_4.setObjectName("label_4")
        self.label_5 = QtWidgets.QLabel(self.centralwidget)
        self.label_5.setGeometry(QtCore.QRect(160, 300, 91, 21))
        self.label_5.setObjectName("label_5")
        self.label_6 = QtWidgets.QLabel(self.centralwidget)
        self.label_6.setGeometry(QtCore.QRect(160, 340, 121, 21))
        self.label_6.setObjectName("label_6")
        self.AnswerLabel_2 = QtWidgets.QLabel(self.centralwidget)
        self.AnswerLabel_2.setGeometry(QtCore.QRect(290, 290, 81, 21))
        self.AnswerLabel_2.setObjectName("AnswerLabel_2")
        self.CheckButton_2 = QtWidgets.QPushButton(self.centralwidget)
        self.CheckButton_2.setGeometry(QtCore.QRect(50, 390, 111, 31))
        self.CheckButton_2.setObjectName("CheckButton_2")
        self.AnswerLabel = QtWidgets.QLabel(self.centralwidget)
        self.AnswerLabel.setGeometry(QtCore.QRect(520, 110, 91, 21))
        self.AnswerLabel.setObjectName("AnswerLabel")
        self.WordBox_1_1 = QtWidgets.QComboBox(self.centralwidget)
        self.WordBox_1_1.setGeometry(QtCore.QRect(390, 260, 111, 22))
        self.WordBox_1_1.setObjectName("WordBox_1_1")
        self.WordBox_1_1.addItem("")
        self.WordBox_1_1.addItem("")
        self.WordBox_1_1.addItem("")
        self.DescBox_1_1 = QtWidgets.QComboBox(self.centralwidget)
        self.DescBox_1_1.setGeometry(QtCore.QRect(530, 260, 111, 22))
        self.DescBox_1_1.setObjectName("DescBox_1_1")
        self.DescBox_1_1.addItem("")
        self.DescBox_1_1.addItem("")
        self.DescBox_1_1.addItem("")
        self.AnswerLabel_3 = QtWidgets.QLabel(self.centralwidget)
        self.AnswerLabel_3.setGeometry(QtCore.QRect(650, 290, 61, 21))
        self.AnswerLabel_3.setObjectName("AnswerLabel_3")
        self.CheckButton_3 = QtWidgets.QPushButton(self.centralwidget)
        self.CheckButton_3.setGeometry(QtCore.QRect(430, 390, 111, 31))
        self.CheckButton_3.setObjectName("CheckButton_3")
        self.WordBox_1_2 = QtWidgets.QComboBox(self.centralwidget)
        self.WordBox_1_2.setGeometry(QtCore.QRect(390, 290, 111, 22))
        self.WordBox_1_2.setObjectName("WordBox_1_2")
        self.WordBox_1_2.addItem("")
        self.WordBox_1_2.addItem("")
        self.WordBox_1_2.addItem("")
        self.WordBox_1_3 = QtWidgets.QComboBox(self.centralwidget)
        self.WordBox_1_3.setGeometry(QtCore.QRect(390, 320, 111, 22))
        self.WordBox_1_3.setObjectName("WordBox_1_3")
        self.WordBox_1_3.addItem("")
        self.WordBox_1_3.addItem("")
        self.WordBox_1_3.addItem("")
        self.DescBox_1_3 = QtWidgets.QComboBox(self.centralwidget)
        self.DescBox_1_3.setGeometry(QtCore.QRect(530, 320, 111, 22))
        self.DescBox_1_3.setObjectName("DescBox_1_3")
        self.DescBox_1_3.addItem("")
        self.DescBox_1_3.addItem("")
        self.DescBox_1_3.addItem("")
        self.DescBox_1_2 = QtWidgets.QComboBox(self.centralwidget)
        self.DescBox_1_2.setGeometry(QtCore.QRect(530, 290, 111, 22))
        self.DescBox_1_2.setObjectName("DescBox_1_2")
        self.DescBox_1_2.addItem("")
        self.DescBox_1_2.addItem("")
        self.DescBox_1_2.addItem("")
        self.CheckButton_4 = QtWidgets.QPushButton(self.centralwidget)
        self.CheckButton_4.setGeometry(QtCore.QRect(480, 190, 81, 23))
        self.CheckButton_4.setObjectName("CheckButton_4")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 732, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

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

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.label_2.setText(_translate("MainWindow", "This is a test text. It\'s main                                    is to understand what can i do and how it is possible to create"))
        self.label.setText(_translate("MainWindow", "This programm is so                                     (progress) and gives me a lot of abillities and it is awesome"))
        self.label_3.setText(_translate("MainWindow", "There are two versions of this programms and they are really "))
        self.AnswerBox.setItemText(0, _translate("MainWindow", "Choose a word"))
        self.AnswerBox.setItemText(1, _translate("MainWindow", "difference"))
        self.AnswerBox.setItemText(2, _translate("MainWindow", "different"))
        self.AnswerBox.setItemText(3, _translate("MainWindow", "indifferent"))
        self.CheckButton.setText(_translate("MainWindow", "Check"))
        self.comboBox_1_1.setItemText(0, _translate("MainWindow", "Car"))
        self.comboBox_1_1.setItemText(1, _translate("MainWindow", "Plane"))
        self.comboBox_1_1.setItemText(2, _translate("MainWindow", "Boat"))
        self.comboBox_1_3.setItemText(0, _translate("MainWindow", "Car"))
        self.comboBox_1_3.setItemText(1, _translate("MainWindow", "Plane"))
        self.comboBox_1_3.setItemText(2, _translate("MainWindow", "Boat"))
        self.comboBox_1_2.setItemText(0, _translate("MainWindow", "Car"))
        self.comboBox_1_2.setItemText(1, _translate("MainWindow", "Plane"))
        self.comboBox_1_2.setItemText(2, _translate("MainWindow", "Boat"))
        self.label_4.setText(_translate("MainWindow", "moves in the air"))
        self.label_5.setText(_translate("MainWindow", "goes on the road"))
        self.label_6.setText(_translate("MainWindow", "moves on the water"))
        self.AnswerLabel_2.setText(_translate("MainWindow", "TextLabel"))
        self.CheckButton_2.setText(_translate("MainWindow", "Check"))
        self.AnswerLabel.setText(_translate("MainWindow", "TextLabel"))
        self.WordBox_1_1.setItemText(0, _translate("MainWindow", "Car"))
        self.WordBox_1_1.setItemText(1, _translate("MainWindow", "Plane"))
        self.WordBox_1_1.setItemText(2, _translate("MainWindow", "Boat"))
        self.DescBox_1_1.setItemText(0, _translate("MainWindow", "moves on the road"))
        self.DescBox_1_1.setItemText(1, _translate("MainWindow", "moves on the water"))
        self.DescBox_1_1.setItemText(2, _translate("MainWindow", "moves in the air"))
        self.AnswerLabel_3.setText(_translate("MainWindow", "TextLabel"))
        self.CheckButton_3.setText(_translate("MainWindow", "Check"))
        self.WordBox_1_2.setItemText(0, _translate("MainWindow", "Car"))
        self.WordBox_1_2.setItemText(1, _translate("MainWindow", "Plane"))
        self.WordBox_1_2.setItemText(2, _translate("MainWindow", "Boat"))
        self.WordBox_1_3.setItemText(0, _translate("MainWindow", "Car"))
        self.WordBox_1_3.setItemText(1, _translate("MainWindow", "Plane"))
        self.WordBox_1_3.setItemText(2, _translate("MainWindow", "Boat"))
        self.DescBox_1_3.setItemText(0, _translate("MainWindow", "moves on the road"))
        self.DescBox_1_3.setItemText(1, _translate("MainWindow", "moves on the water"))
        self.DescBox_1_3.setItemText(2, _translate("MainWindow", "moves in the air"))
        self.DescBox_1_2.setItemText(0, _translate("MainWindow", "moves on the road"))
        self.DescBox_1_2.setItemText(1, _translate("MainWindow", "moves on the water"))
        self.DescBox_1_2.setItemText(2, _translate("MainWindow", "moves in the air"))
        self.CheckButton_4.setText(_translate("MainWindow", "Check"))

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

        self.CheckButton.clicked.connect(self.checkanswer1)
        self.CheckButton_2.clicked.connect(self.checkanswer2)

        self.a = " "
        self.b = " "

    def setanswer1(self):
        self.a = self.AnswerEdit.text()
        self.b = self.lineEdit_2.text()

    def checkanswer1(self):
        self.setanswer1()
        if str(self.a) == "aim":
            self.AnswerEdit.setStyleSheet("QLineEdit { color : green}")
        elif str(self.a) == "":
            pass
        else:
            self.AnswerEdit.setStyleSheet("QLineEdit { color : red}")

        if str(self.b) == "progressive" :
            self.lineEdit_2.setStyleSheet("QLineEdit { color : green}")
        elif str(self.b) == "" :
            pass
        else:
            self.lineEdit_2.setStyleSheet("QLineEdit { color : red}")

    def checkanswer2(self):
        if self.comboBox_1_1.currentText() == "Car":
            self.AnswerLabel_2.setText('good job')
# +++ vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
            self.setStyleSheet(""" 
                QComboBox#comboBox_1_1 {
                    background: red;
                    color: #fff;
                }
                QLabel#AnswerLabel_2 {
                    background: red;
                    color: #fff;
                }
            """)
# +++ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        else:
            self.AnswerLabel_2.setText("Try again")
            self.setStyleSheet("")                                       # +++



if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    w = MainWindow()
    w.show()
    sys.exit(app.exec_())

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

2
  • Спасибо большое за помощь! А можно ли изменять цвет шрифта выпадающих списков?
    – Mswork6
    Commented 19 июн. 2020 в 8:14
  • @Mswork6 все можно, задайте новый вопрос.
    – S. Nick
    Commented 19 июн. 2020 в 10:10

Ваш ответ

Нажимая «Отправить ответ», вы соглашаетесь с условиями пользования и подтверждаете, что прочитали политику конфиденциальности.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.