Wxwidgets 和 Pyqt [英] Wxwidgets and Pyqt
本文介绍了Wxwidgets 和 Pyqt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Pyqt 中是否有类似的函数 PyOnDemandOutputWindow?此函数将控制台输出重定向到一个单独的窗口.
Is there a similar function PyOnDemandOutputWindow in Pyqt? This function redirect the console output to a separate window.
推荐答案
可以将 sys.std[out|err]
替换为将所有输出写入到例如一个 QPlainTextEdit.一个非常基本的例子:
It is possible to replace sys.std[out|err]
with a wrapper that writes all output to e.g. a QPlainTextEdit. A very basic example:
class StdoutWrapper(object):
def __init__(self, outwidget):
self.widget = outwidget
self.widget.setReadOnly(True) # assuming QPlainTextEdit
self.widget.hide()
def write(self, s):
self.widget.show()
self.widget.appendPlainText(s) # again assuming QPlainTextEdit
还有其他地方:
import sys
sys.stdout = StdoutWrapper(yourwidget)
# similar for stderr, but you might want an error dialog or make
# the text stand out using appendHtml
这篇关于Wxwidgets 和 Pyqt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文