Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Python has stopped working / AttributeError: 'Ui_Form' object has no attribute 'lineEdit'
Qt 6.12 LTS is out! See what's new in the release blog

Python has stopped working / AttributeError: 'Ui_Form' object has no attribute 'lineEdit'

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jerap
    wrote on last edited by
    #1

    I want to set the label in B.py to whatever the user typed in A.py self.lineEdit. However, when I clicked the button in A.py, the application crashed and display this message: Python has stopped working. Then I ran B.py to see what is the problem and this error shows: AttributeError: 'Ui_Form' object has no attribute 'lineEdit'.

    A.py
    
    from PyQt6 import QtCore, QtGui, QtWidgets
    import B
    
    class Ui_Form(object):
        def setupUi(self, Form):
            Form.setObjectName("Form")
            Form.resize(203, 146)
            self.verticalLayout = QtWidgets.QVBoxLayout(Form)
            self.verticalLayout.setContentsMargins(0, 0, 0, 0)
            self.verticalLayout.setSpacing(0)
            self.verticalLayout.setObjectName("verticalLayout")
            self.lineEdit = QtWidgets.QLineEdit(Form)
            self.lineEdit.setObjectName("lineEdit")
            self.verticalLayout.addWidget(self.lineEdit)
            self.pushButton = QtWidgets.QPushButton(Form)
            self.pushButton.setObjectName("pushButton")
            self.verticalLayout.addWidget(self.pushButton)
    
            self.retranslateUi(Form)
            QtCore.QMetaObject.connectSlotsByName(Form)
    
            self.pushButton.clicked.connect(self.enter)
            self.pushButton.clicked.connect(Form.close)
    
        def retranslateUi(self, Form):
            _translate = QtCore.QCoreApplication.translate
            Form.setWindowTitle(_translate("Form", "Form"))
            self.pushButton.setText(_translate("Form", "Enter"))
    
        def enter(self):
            self.lineedit_txt = self.lineEdit.text()
    
            self.window_login1 = QtWidgets.QWidget()
            self.ui_login1 = B.Ui_Form()
            self.ui_login1.setupUi2(self.window_login1)
            self.window_login1.show()
    
    if __name__ == "__main__":
        import sys
        app = QtWidgets.QApplication(sys.argv)
        Form = QtWidgets.QWidget()
        ui = Ui_Form()
        ui.setupUi(Form)
        Form.show()
        sys.exit(app.exec())
    
    B.py
    
    from PyQt6 import QtCore, QtGui, QtWidgets
    
    
    class Ui_Form(object):
        def setupUi2(self, Form):
            Form.setObjectName("Form")
            Form.resize(400, 300)
            self.verticalLayout = QtWidgets.QVBoxLayout(Form)
            self.verticalLayout.setObjectName("verticalLayout")
            self.label = QtWidgets.QLabel(Form)
            self.label.setText("")
            self.label.setObjectName("label")
            self.verticalLayout.addWidget(self.label)
    
            self.retranslateUi(Form)
            QtCore.QMetaObject.connectSlotsByName(Form)
    
            self.output()
    
        def retranslateUi(self, Form):
            _translate = QtCore.QCoreApplication.translate
            Form.setWindowTitle(_translate("Form", "Form"))
          
        def output(self):
            import A
            obj = A.Ui_Form()
            obj.enter()
    
            txt_for_label = obj.lineedit_txt
            self.label.setText(txt_for_label)
    
    if __name__ == "__main__":
        import sys
        app = QtWidgets.QApplication(sys.argv)
        Form = QtWidgets.QWidget()
        ui = Ui_Form()
        ui.setupUi2(Form)
        Form.show()
        sys.exit(app.exec())
    
    
    JonBJ 1 Reply Last reply
    0
    • J jerap

      I want to set the label in B.py to whatever the user typed in A.py self.lineEdit. However, when I clicked the button in A.py, the application crashed and display this message: Python has stopped working. Then I ran B.py to see what is the problem and this error shows: AttributeError: 'Ui_Form' object has no attribute 'lineEdit'.

      A.py
      
      from PyQt6 import QtCore, QtGui, QtWidgets
      import B
      
      class Ui_Form(object):
          def setupUi(self, Form):
              Form.setObjectName("Form")
              Form.resize(203, 146)
              self.verticalLayout = QtWidgets.QVBoxLayout(Form)
              self.verticalLayout.setContentsMargins(0, 0, 0, 0)
              self.verticalLayout.setSpacing(0)
              self.verticalLayout.setObjectName("verticalLayout")
              self.lineEdit = QtWidgets.QLineEdit(Form)
              self.lineEdit.setObjectName("lineEdit")
              self.verticalLayout.addWidget(self.lineEdit)
              self.pushButton = QtWidgets.QPushButton(Form)
              self.pushButton.setObjectName("pushButton")
              self.verticalLayout.addWidget(self.pushButton)
      
              self.retranslateUi(Form)
              QtCore.QMetaObject.connectSlotsByName(Form)
      
              self.pushButton.clicked.connect(self.enter)
              self.pushButton.clicked.connect(Form.close)
      
          def retranslateUi(self, Form):
              _translate = QtCore.QCoreApplication.translate
              Form.setWindowTitle(_translate("Form", "Form"))
              self.pushButton.setText(_translate("Form", "Enter"))
      
          def enter(self):
              self.lineedit_txt = self.lineEdit.text()
      
              self.window_login1 = QtWidgets.QWidget()
              self.ui_login1 = B.Ui_Form()
              self.ui_login1.setupUi2(self.window_login1)
              self.window_login1.show()
      
      if __name__ == "__main__":
          import sys
          app = QtWidgets.QApplication(sys.argv)
          Form = QtWidgets.QWidget()
          ui = Ui_Form()
          ui.setupUi(Form)
          Form.show()
          sys.exit(app.exec())
      
      B.py
      
      from PyQt6 import QtCore, QtGui, QtWidgets
      
      
      class Ui_Form(object):
          def setupUi2(self, Form):
              Form.setObjectName("Form")
              Form.resize(400, 300)
              self.verticalLayout = QtWidgets.QVBoxLayout(Form)
              self.verticalLayout.setObjectName("verticalLayout")
              self.label = QtWidgets.QLabel(Form)
              self.label.setText("")
              self.label.setObjectName("label")
              self.verticalLayout.addWidget(self.label)
      
              self.retranslateUi(Form)
              QtCore.QMetaObject.connectSlotsByName(Form)
      
              self.output()
      
          def retranslateUi(self, Form):
              _translate = QtCore.QCoreApplication.translate
              Form.setWindowTitle(_translate("Form", "Form"))
            
          def output(self):
              import A
              obj = A.Ui_Form()
              obj.enter()
      
              txt_for_label = obj.lineedit_txt
              self.label.setText(txt_for_label)
      
      if __name__ == "__main__":
          import sys
          app = QtWidgets.QApplication(sys.argv)
          Form = QtWidgets.QWidget()
          ui = Ui_Form()
          ui.setupUi2(Form)
          Form.show()
          sys.exit(app.exec())
      
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @jerap
      Let's start with:

      # In `A.enter()`
      self.ui_login1 = B.Ui_Form()
      
      # In `B.output()`
              import A
              obj = A.Ui_Form()
              obj.enter()
      

      That does not look very promising, crash-wise....

      Next: when as above in B.output() you do go

              import A
              obj = A.Ui_Form()
              obj.enter()
      

      you have never gone A.Ui_Form.setupUi() so your A.Form does not have any self.lineEdit, doubtless hence the error message.

      Don't know what you're trying to do with this convolution, but you'd better sort your instances of A & B out because I suspect you're failing to understand correctly accessing existing instances and creating new ones afresh without understanding.

      J 1 Reply Last reply
      1
      • JonBJ JonB

        @jerap
        Let's start with:

        # In `A.enter()`
        self.ui_login1 = B.Ui_Form()
        
        # In `B.output()`
                import A
                obj = A.Ui_Form()
                obj.enter()
        

        That does not look very promising, crash-wise....

        Next: when as above in B.output() you do go

                import A
                obj = A.Ui_Form()
                obj.enter()
        

        you have never gone A.Ui_Form.setupUi() so your A.Form does not have any self.lineEdit, doubtless hence the error message.

        Don't know what you're trying to do with this convolution, but you'd better sort your instances of A & B out because I suspect you're failing to understand correctly accessing existing instances and creating new ones afresh without understanding.

        J Offline
        J Offline
        jerap
        wrote on last edited by
        #3

        @JonB
        What I want to do is to set the text of B.self.label to whatever the user inputs in A.self.lineEdit.

        JonBJ 1 Reply Last reply
        0
        • J jerap

          @JonB
          What I want to do is to set the text of B.self.label to whatever the user inputs in A.self.lineEdit.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @jerap
          You need to start by sorting out your architecture before that. How are A and B related? Which one shows which one? Is only one at a time supposed to be visible, are they both supposed to be visible all the time? I suggest you don't worry about the label till you have that sorted out.

          Then they way to pass information between one and the other will be clearer.

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt
          • Unsolved