2024-04-25 16:54:52 发布
网友
我用Python制作了一个软件,使用Tkinter进行图形和ctypes,以便与公司给我的一些C库进行接口。 很多操作我都会在终端上打印输出,所以我想知道:有没有一种简单的方法可以将这些输出消息重定向到另一个tkinter窗口? 例如,我想打印一个cout<;<;“你好,世界!”在一个新的冬天,连接到根一,而不是终端,这是可能的吗?你知道吗
您可以覆盖sys.stdout:
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 anything import sys sys.stdout = WriteToWindow()
现在,写入stdout的所有内容,包括对print的调用,都将发送到WriteToWindow类。你知道吗
print
WriteToWindow
您可以覆盖
sys.stdout
:现在,写入stdout的所有内容,包括对
print
的调用,都将发送到WriteToWindow
类。你知道吗相关问题 更多 >
编程相关推荐