您可以覆盖sys.stdout:class WriteToWindow(): def write(self, text): ... # write text to your window def flush(self): pass # this method should exist, but doesn't need to do anythingimport syssys.stdout = WriteToWindow()现在写入标准输出的所有内容,包括对 的调用print,都将发送到您的WriteToWindow类。