2017-10-03 12 views
0

私はQLineEdit.text()から入力を取得する方法についていくつかの質問を検索しましたが、それは自分のコードでは機能しません。どうしてか分かりません。QLineEdit()。text()が私のコードで動作しないのはなぜですか?

マイコード:

import sys 
from PyQt5.QtWidgets import (QApplication, QWidget,QPushButton,QLineEdit) 

class Login_Ui(QWidget): 
    def __init__(self): 
     super().__init__() 
     self.initUI() 

    def initUI(self): 
     self.setWindowTitle('form') 

     self.AccoutText = QLineEdit(self) 
     self.AccoutText.setGeometry(140,185,180,30) 
     self.username = self.AccoutText.text()#### 

     self.PwdText = QLineEdit(self) 
     self.PwdText.setGeometry(140,220,180,30) 
     self.password = self.PwdText.text()#### 

     self.LoginBtn = QPushButton('login',self) 
     self.LoginBtn.clicked.connect(self.loginme) 
     self.LoginBtn.setGeometry(140,290,180,30) 
     self.show() 

    def loginme(self): 
     print(self.username) 
     print(self.password) 
     print('...') 

if __name__ == '__main__': 
    app = QApplication(sys.argv) 
    Log = Login_Ui() 
    sys.exit(app.exec_()) 
+0

あなたは「うまくいかない」以上のことを説明する必要があります。 – Ajean

答えて

1

何がそれらに置かれる前に、あなたはそれらのtexteditsからテキストを保存しているので、それは働いていません。

loginボタンを押すと、texteditsからテキストを取得する必要があります。このように:

def loginme(self): 
    # get the values from the textedits first 
    self.username = self.AccoutText.text() 
    self.password = self.PwdText.text() 

    print(self.username) 
    print(self.password) 
    print('...') 
関連する問題