Answer the question
In order to leave comments, you need to log in
PyQt5 How to assign text from QLineEdit to variable?
I'm making a big application, everything hangs on the line a = self.lineEdit_1.toPlainText(), now I'm trying to make a small program with only this function to understand what's going on, but then everything crashes on the same line.
We need to assign the text from lineEdit_1 to the variable a, then display the text of variable a in lineEdit_2.
What am I doing wrong?( Thanks in advance for your help :)
from PyQt5 import QtCore, QtGui, QtWidgets
class MyWin(QtWidgets.QMainWindow):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.pushButton.clicked.connect(self.btnClicked)
def btnClicked(self):
a = self.lineEdit_1.toPlainText()
self.ui.lineEdit_2.setPlainText(a)
app = QtWidgets.QApplication([])
application = MyWin()
application.show()
sys.exit(app.exec())
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question