[英]Why the QLineEdit().text() doesn't work in my code?
我已經搜索了幾個有關如何從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_())
這是行不通的,因為您要先存儲來自這些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('...')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.