I
I
Ivan Demianov2020-09-25 17:31:44
Python
Ivan Demianov, 2020-09-25 17:31:44

Error in PyQt5 AttributeError: 'QWidget' object has no attribute 'text'. What to do?

Making a PyQt design:

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

# Form implementation generated from reading ui file 'test.ui'
#
# Created by: PyQt5 UI code generator 5.15.0
#
# 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_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(118, 100)
        self.comboBox = QtWidgets.QComboBox(Form)
        self.comboBox.setGeometry(QtCore.QRect(10, 60, 101, 32))
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.label = QtWidgets.QLabel(Form)
        self.label.setGeometry(QtCore.QRect(10, -20, 121, 100))
        self.label.setObjectName("label")

        self.retranslateUi(Form)
        self.comboBox.editTextChanged['QString'].connect(Form.text)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.comboBox.setItemText(0, _translate("Form", "Admin For"))
        self.label.setText(_translate("Form", "Виберіть режим"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Form = QtWidgets.QWidget()
    ###########################################
    def text():
        print(QString.editTextChanged)
    ###########################################
    ui = Ui_Form()
    ui.setupUi(Form)
    Form.show()
    sys.exit(app.exec_())

Mistake:
Traceback (most recent call last):
  File "/Users/polina/Desktop/VS_NOTES_VERSIOn_6.2/test.py", line 51, in <module>
    ui.setupUi(Form)
  File "/Users/polina/Desktop/VS_NOTES_VERSIOn_6.2/test.py", line 27, in setupUi
    self.comboBox.editTextChanged['QString'].connect(Form.text)
AttributeError: 'QWidget' object has no attribute 'text'

What to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav the Wise, 2020-09-25
@yungtitanium

Read the documentation, what attributes are in the Form

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question