How to redirect print result from python shell into qtextedit pyqt?

半世苍凉 提交于 2019-12-08 12:18:00

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!