1

I am trying to assign the text input (Username and password) to a new variable (IPassword and IUsername) to be used in other def's. I cant get it to work, When running the code i get the following error 'Error: Can't assign to function call'. The code is below:

class LoginWidget(QtGui.QWidget):
    success = QtCore.pyqtSignal()
    def __init__(self, parent=None):
        super(LoginWidget, self).__init__(parent)
        self.Username = QtGui.QLineEdit(self)  
        self.Password = QtGui.QLineEdit(self)
        self.Password.text() = IPassword
        self.Username.text() = IUsername
        self.buttonLogin = QtGui.QPushButton('Login', self)
        self.buttonLogin.clicked.connect(self.handleLogin)
    def handleLogin(self):
        global IPassword
        global IUsername
Hamzah Akhtar
  • 525
  • 5
  • 13
  • 24

1 Answers1

1

You can't assign values to function calls. So, you can't do that:

self.Password.text() = IPassword
self.Username.text() = IUsername

The correct way to do it, is:

self.Password.setText(IPassword)
self.Username.setText(IUsername)

I hope it helps.

Amaury Medeiros
  • 2,093
  • 4
  • 26
  • 42
  • Will this set the input text as IPassword (changing the input) or would it assign the input to a created variable IPassword?? – Hamzah Akhtar Apr 03 '14 at 18:02
  • It will change the input. If you want to get the content of those fields inside the handlelogin method, you should use something like password = self.Password.text(). Then, handle the variable inside the method. – Amaury Medeiros Apr 03 '14 at 18:08
  • Thanks, that was the answer i was looking for (password = self.Password.text()) it didn't work for me because i wrote it the other way around although i thought that it wouldn't make a difference. – Hamzah Akhtar Apr 03 '14 at 18:20