Создание нового QtLabel

Рейтинг: 0Ответов: 1Опубликовано: 01.04.2023

Я сгенерировал через QtDesigner окно, теперь я хочу создать новый QtLabel на все окно так, чтобы оно не открывалось в новом окне. Я пытался создать в MainWidnow1 QtLabel, где в скобках написал cityquwstion1, была ошибка. Когда оставил скобки пустые, тогда открывался Qtlabel в новом окне.

    import sys, os
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *

class Ui_cityquestion1(object):
    def setupUi(self, cityquestion1):
        cityquestion1.setObjectName("cityquestion1")
        cityquestion1.resize(1223, 800)
        cityquestion1.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.task = QtWidgets.QLabel(cityquestion1)
        self.task.setGeometry(QtCore.QRect(0, 0, 1231, 81))
        self.task.setStyleSheet("color: #000;\n"
"font: 24pt \"MS Shell Dlg 2\";\n"
"border: none;\n"
"color: white;\n"
"background-color: rgb(214, 146, 255);")
        self.task.setAlignment(QtCore.Qt.AlignCenter)
        self.task.setObjectName("task")
        self.answer1 = QtWidgets.QPushButton(cityquestion1)
        self.answer1.setGeometry(QtCore.QRect(240, 520, 291, 81))
        font = QtGui.QFont()
        font.setFamily("MS Shell Dlg 2")
        font.setPointSize(24)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.answer1.setFont(font)
        self.answer1.setStyleSheet("border: none;\n"
"color: rgb(0, 0, 0);\n"
"font: 24pt \"MS Shell Dlg 2\";\n"
"border: none;\n"
"color: white;\n"
"background-color: rgb(112, 107, 255);\n"
"border-radius: 10px")
        self.answer1.setObjectName("answer1")
        self.answer2 = QtWidgets.QPushButton(cityquestion1)
        self.answer2.setGeometry(QtCore.QRect(690, 520, 291, 81))
        font = QtGui.QFont()
        font.setFamily("MS Shell Dlg 2")
        font.setPointSize(24)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.answer2.setFont(font)
        self.answer2.setStyleSheet("border: none;\n"
"color: rgb(0, 0, 0);\n"
"font: 24pt \"MS Shell Dlg 2\";\n"
"border: none;\n"
"color: white;\n"
"border-radius: 10px;\n"
"background-color: rgb(112, 107, 255);")
        self.answer2.setObjectName("answer2")
        self.answer3 = QtWidgets.QPushButton(cityquestion1)
        self.answer3.setGeometry(QtCore.QRect(240, 650, 291, 81))
        font = QtGui.QFont()
        font.setFamily("MS Shell Dlg 2")
        font.setPointSize(24)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.answer3.setFont(font)
        self.answer3.setStyleSheet("border: none;\n"
"color: rgb(0, 0, 0);\n"
"font: 24pt \"MS Shell Dlg 2\";\n"
"border: none;\n"
"color: white;\n"
"background-color: rgb(112, 107, 255);\n"
"border-radius: 10px")
        self.answer3.setObjectName("answer3")
        self.answer4 = QtWidgets.QPushButton(cityquestion1)
        self.answer4.setGeometry(QtCore.QRect(690, 650, 291, 81))
        font = QtGui.QFont()
        font.setFamily("MS Shell Dlg 2")
        font.setPointSize(24)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.answer4.setFont(font)
        self.answer4.setStyleSheet("border: none;\n"
"color: rgb(0, 0, 0);\n"
"font: 24pt \"MS Shell Dlg 2\";\n"
"border: none;\n"
"color: white;\n"
"border-radius: 10px;\n"
"background-color: rgb(112, 107, 255);")
        self.answer4.setObjectName("answer4")
        self.label = QtWidgets.QLabel(cityquestion1)
        self.label.setGeometry(QtCore.QRect(240, 100, 741, 381))
        self.label.setText("")
        self.label.setPixmap(QtGui.QPixmap("questionsimages/city/cityquestion1.jpg"))
        self.label.setObjectName("label")

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

    def retranslateUi(self, cityquestion1):
        _translate = QtCore.QCoreApplication.translate
        cityquestion1.setWindowTitle(_translate("cityquestion1", "Form"))
        self.task.setText(_translate("cityquestion1", "Toto mesto, hlavné mesto ktorej krajiny ?"))
        self.answer1.setText(_translate("cityquestion1", "Rusko"))
        self.answer2.setText(_translate("cityquestion1", "Bielorusko"))
        self.answer3.setText(_translate("cityquestion1", "Francúzsko"))
        self.answer4.setText(_translate("cityquestion1", "Fínsko"))

class MainWindow1(QtWidgets.QMainWindow, Ui_cityquestion1):
    def __init__(self):
        super().__init__()
         "код для QtLabel"
        

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

Ответы

▲ 0Принят

Просто в скобках писать self. Qlabel(self)