Форум сайта python.su
Добрый день помогите пожалуйста. Пытаюсь передать данные при нажатии на кнопку в textEdit но выходит ошибкаю Вот код, что надо поправить
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(“MainWindow”)
MainWindow.resize(982, 743)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName(“centralwidget”)
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(40, 340, 93, 28))
self.pushButton.setObjectName(“pushButton”)
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
self.textEdit.setGeometry(QtCore.QRect(43, 46, 741, 261))
self.textEdit.setObjectName(“textEdit”)
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(250, 350, 431, 281))
self.lineEdit.setObjectName(“lineEdit”)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 982, 26))
self.menubar.setObjectName(“menubar”)
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName(“statusbar”)
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.add_functions()
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate(“MainWindow”, “MainWindow”))
self.pushButton.setText(_translate(“MainWindow”, “PushButton”))
def add_functions(self):
self.pushButton.clicked.connect(lambda: self.write_number(self.pushButton.text()))
def write_number(self, number):
self.textEdit.setPlainText (self.textEdit() + number)
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_())
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file ‘ui.ui’
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(“MainWindow”)
MainWindow.resize(982, 743)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName(“centralwidget”)
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(40, 340, 93, 28))
self.pushButton.setObjectName(“pushButton”)
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
self.textEdit.setGeometry(QtCore.QRect(43, 46, 741, 261))
self.textEdit.setObjectName(“textEdit”)
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(250, 350, 431, 281))
self.lineEdit.setObjectName(“lineEdit”)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 982, 26))
self.menubar.setObjectName(“menubar”)
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName(“statusbar”)
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.add_functions()
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate(“MainWindow”, “MainWindow”))
self.pushButton.setText(_translate(“MainWindow”, “PushButton”))
def add_functions(self):
self.pushButton.clicked.connect(lambda: self.write_number(self.pushButton.text()))
def write_number(self, number):
self.textEdit.setPlainText (self.textEdit() + number)
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_())
выходит ошибка
TypeError: ‘QTextEdit’ object is not callable
вывод нужен именно в textEdit , в lineedit вывожу без проблем
Офлайн
Оберните код в тег - ничитабельно
Офлайн
da_zanyti_vse_imenaself.textEdit.setPlainText (self.textEdit() + number)
self.textEdit.setPlainText(self.textEdit.toPlainText() + str(number))
Офлайн