문제

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
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top