首页 > 解决方案 > GUI 屏幕中的 print() 输出

问题描述

我希望有人能帮助我。

基本上,我有一个任意脚本,在这个脚本中,有很多函数,在每个函数执行后,print() 也会执行给我一个更新。我正在使用用于 GUI 的 Pysimplegui 库,并且想知道是否有人可以帮助或解释我可以做些什么来在 GUI 中显示打印输出

标签: pythonpysimplegui

解决方案


文档中有几种方法可以做到这一点,这是一种方法。

import PySimpleGUI as sg

# This is the normal print that comes with simple GUI
sg.Print('Re-routing the stdout', do_not_reroute_stdout=False)

# this is clobbering the print command, and replacing it with sg's Print()
print = sg.Print

# this will now output to the sg display.
print('This is a normal print that has been re-routed.')

这是示例输出

在此处输入图像描述


推荐阅读