Answer the question
In order to leave comments, you need to log in
Can't see PyQt class parameter?
Hello everyone, I decided to write a simple program with a graphical interface in PyQt, Designer.
Everything went well at first, but as soon as I started trying to change the python code of the program itself, I got this error:
Traceback (most recent call last):
File "D:\Python\programm\python.py", line 11, in
File " D:\Python\programm\design.py", line 51, in setupUi
AttributeError: 'PySide2.QtWidgets.QDialog' object has no attribute 'setCentralWidget'
It doesn't see the CentrallWidget attribute, and I don't understand why or how to solve this problem .
Please, help.
Source code of the first program file:
from PySide2.QtGui import *
from PySide2.QtWidgets import *
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
if not MainWindow.objectName():
MainWindow.setObjectName(u"MainWindow")
MainWindow.resize(471, 474)
MainWindow.setLayoutDirection(Qt.LeftToRight)
MainWindow.setStyleSheet(u"font: 8pt \"Segoe UI Semilight\";")
self.centralwidget = QWidget(MainWindow)
self.centralwidget.setObjectName(u"centralwidget")
self.pushButton = QPushButton(self.centralwidget)
self.pushButton.setObjectName(u"pushButton")
self.pushButton.setGeometry(QRect(110, 160, 231, 51))
self.pushButton.setStyleSheet(u"QPushButton{\n"
" background-color:black;\n"
" color:yellow;\n"
" font: 16pt \"MS Shell Dlg 2\";\n"
" \n"
" font: 25 14pt \"Segoe UI Light\";\n"
" border-radius:20px;\n"
"}\n"
"QPushButton:pressed{\n"
" color:orange}\n"
"")
self.lineEdit = QLineEdit(self.centralwidget)
self.lineEdit.setObjectName(u"lineEdit")
self.lineEdit.setGeometry(QRect(90, 50, 281, 61))
self.lineEdit.setStyleSheet(u"background-color:black;\n"
"font: 25 18pt \"Segoe UI Light\";\n"
"color:yellow;\n"
"border-radius:20px;")
self.label = QLabel(self.centralwidget)
self.label.setObjectName(u"label")
self.label.setGeometry(QRect(0, 230, 461, 211))
self.label.setLayoutDirection(Qt.LeftToRight)
self.label.setStyleSheet(u"")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QMenuBar(MainWindow)
self.menubar.setObjectName(u"menubar")
self.menubar.setGeometry(QRect(0, 0, 471, 23))
MainWindow.setMenuBar(self.menubar)
self.statusbar = QStatusBar(MainWindow)
self.statusbar.setObjectName(u"statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QMetaObject.connectSlotsByName(MainWindow)
# setupUi
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None))
self.pushButton.setText(QCoreApplication.translate("MainWindow", u"\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c", None))
self.label.setText(QCoreApplication.translate("MainWindow", u"\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442", None))
# retranslateUi
import sys
from PySide2 import QtCore,QtGui,QtWidgets
from design import Ui_MainWindow
#Create app
app = QtWidgets.QApplication(sys.argv)
# init
Dialog = QtWidgets.QDialog()
ui = Ui_MainWindow()
ui.setupUi(Dialog)
Dialog.show()
#Hook Logic
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question