问题
I want my output to appear in my pyqt textedit not python shell after clicking a pushbutton. I am not familiar with subprocess or stdout stuff and not even sure if this will involve them. Need some help here. Here is part of my code:
self.textEdit = QtGui.QTextEdit(Dialog)
self.textEdit.setGeometry(QtCore.QRect(20, 200, 431, 241))
self.textEdit.setObjectName(_fromUtf8("textEdit"))
def readI2C(self):
data = i2c.read_byte(0x50)
return data
self.textEdit.setText(data)
This code does not print anything. I tried it with print data
but this prints result in python shell. Anyone can help?
回答1:
Place this line self.textEdit.setText(data)
before return data
. Once you return value from method, lines after return will not execute.
Also, if you're going to use textEdit only for output (not for editing) set self.textEdit.setReadOnly(1)
来源:https://stackoverflow.com/questions/24878492/how-to-redirect-print-result-from-python-shell-into-qtextedit-pyqt