Raghavendra MG
Raghavendra MG

Reputation: 89

Pyside: QLineEdit taking multiple inputs

I have developed a GUI in Qt Designer in which user can enter two values in the QLineEdit and when the user hits enter it performs some mathematical calculations.

The issue is once the values are entered and enter is pressed after the output I am not able to type in inputs to the QLineEdit but have to restart the GUI every time. Here is my code:

    def entervalues(self):
        if self.RotationEdit.text() != "" and self.TiltEdit.text() != "":
            self.RotationEdit = str(self.RotationEdit.text())
            self.TiltEdit = str(self.TiltEdit.text())
            self.pass_arguments.emit("self.RotationEdit","self.TiltEdit")
        else:
            QMessageBox.information(self, "Error","No Values Entered")

If I try to enter values and hit enter it gives out Attribute Error.

    line 100, in entervalues
    if self.RotationEdit.text() != "" and self.TiltEdit.text() != "":
    AttributeError: 'str' object has no attribute 'text'

enter image description here

Upvotes: 1

Views: 783

Answers (1)

eyllanesc
eyllanesc

Reputation: 243907

The problem arises that in your code you are changing the object self.RotationEdit

self.RotationEdit = str(self.RotationEdit.text())

When you initially declare this is a QLineEdit, but then you assign a String. When you reuse it this will still be string so the text() function is not defined. I recommend creating a new variable that contains the values ​​that you will use in another function.

def entervalues(self):
    if self.RotationEdit.text() != "" and self.TiltEdit.text() != "":
        self.pass_arguments.emit(self.RotationEdit.text(),self.TiltEdit.text())
    else:
        QMessageBox.information(self, "Error","No Values Entered")

Upvotes: 1

Related Questions